/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import ExcelAccess.AllocateFile;
import ExcelAccess.ExcelExporter;
import ExcelAccess.ExcelFormat;
import Message.LoginMessage;
import Message.QueryMessage;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;

/**
 *
 * @author workshop
 */
public class Login extends javax.swing.JFrame {

    Socket localSocket = null;
    String hostName = "localhost";
    int portNumber = 7799;
    LoginMessage loginMsn = null;
    
    Dimension userManageViewDim = new Dimension(600,650);
    Dimension mainViewDim = new Dimension(1150, 720);
    Dimension objectViewDim = new Dimension(950,720);
    
    Dimension userTableDim = new Dimension(400, 500);
    Dimension loginDim = new Dimension(420,500);
    Dimension objectsTableDim = new Dimension(600,500);
    Dimension objectsSearchDim = new Dimension(600,50);
    
    Dimension serviceCallSearchDim = new Dimension(800,75);
    Dimension serviceCallSearchInsideDim = new Dimension(4000,75);
    
    Dimension serviceCallTableDim = new Dimension(800,500);
    Dimension serviceCallInputDim = new Dimension(700,200);
    
    Dimension inputCellDim = new Dimension(150,150);
    
    int[] serviceCallTableWidth = {100,100,100,100,150,300,100,100,
        100,100,300,300,100,300,300,
        300,100,300,100,150,150,
        300,300,300};
    
    String[] securityOptions = {"Admin", "Manager", "Commitor", "Viewer"};
    String[] objectsFields = {"Object","Ordernumber","Client","Vessel","Equipment","Year Built"};
    Integer[] objectsFieldsType = {QueryMessage.STRING_TYPE,QueryMessage.STRING_TYPE,QueryMessage.STRING_TYPE,QueryMessage.STRING_TYPE,
        QueryMessage.STRING_TYPE,QueryMessage.INT_TYPE};
    
    String[] serviceCallsFields = {"object","Service No","Call No","Status","Responsible","Type of Issue","Priority","Attended By",
        "Location","Date","Reason","Involve System","Down Time","Root Cause Group","Root Cause",
        "Rectification","Repair Time","Part Replaced","Part Brand","Part Manuf Number","Part Isah Number",
        "Service Report","Recommendations","Remarks"};
    Integer[] serviceCallsFieldsType;
    
    String tempDir = System.getProperty("user.dir") + "/tempDir";
    
    private void readConfigFile(){
        FileReader configFile = null;
        String line = null;
        try {
             configFile = new FileReader("config.txt");
             BufferedReader br = new BufferedReader(configFile);
             line = br.readLine();
        } catch (FileNotFoundException ex) {
            JOptionPane.showMessageDialog(this, "Cannot find config.txt in the server root directory, using local server instead"
                    ,"Error",JOptionPane.ERROR_MESSAGE);
            return;
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "config.txt read error" + ex.getMessage()+", using local server instead"
                    ,"Error",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(line == null){
            JOptionPane.showMessageDialog(this, "config.txt is empty, client using local server istead",
                    "Error",JOptionPane.ERROR_MESSAGE);
            return;
        }
        StringTokenizer st = new StringTokenizer(line);
        if(st.countTokens() != 2){
            JOptionPane.showMessageDialog(this, "config.txt format problem, using local server instead, should be \"ip\" then empty space followed by the ip address, client using local server instead"
                    ,"Error",JOptionPane.ERROR_MESSAGE);
            return;
        }
        if(st.nextToken().equalsIgnoreCase("ip")){
            this.hostName = st.nextToken();
            JOptionPane.showMessageDialog(this, "connecting to server at ip: " + this.hostName
                    ,"Connection",JOptionPane.PLAIN_MESSAGE);
        }else{
            JOptionPane.showMessageDialog(this, "config.txt format problem, using local server instead, should be \"ip\" then empty space followed by the ip address, client using local server instead"
                    ,"Error",JOptionPane.ERROR_MESSAGE);
        }
    }
    /**
     * Creates new form Login
     */
    public Login() {
        initComponents();
        this.setTitle("Welcome to Huisman Database");
        this.setIconImage(new ImageIcon(System.getProperty("user.dir")+"\\huisman_icon.jpg").getImage());
        
        serviceCallsFieldsType = new Integer[serviceCallsFields.length];
        for(int i = 0; i < serviceCallsFields.length; i++) serviceCallsFieldsType[i] = QueryMessage.STRING_TYPE;
        
        this.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                if (localSocket != null && loginMsn != null) {
                    QueryMessage terminateMsn = new QueryMessage();
                    try {
                        OutputStream os = localSocket.getOutputStream();
                        ObjectOutputStream oos = new ObjectOutputStream(os);
                        oos.writeObject(terminateMsn);
                        FileUtils.deleteDirectory(new File(tempDir));
                        } catch (Exception ex) {
                        System.err.println("Client terminate with error "+ex.getMessage());
                        System.exit(1);
                    }
                }
                System.exit(0);
            }
        });
        
        this.jMenu.setVisible(false);
        this.jLogin.setSize(this.loginDim);
        this.jMainView.setVisible(false);
        this.setResizable(false);
        
        ((DefaultTableCellRenderer)jTable.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(JLabel.CENTER);
        jTable.setSelectionBackground(Color.CYAN);
        jTable.setAutoCreateRowSorter(true);
        
        // set frame location
        setWindowCenter();
        initSearchPanels();
        readConfigFile();
        
        this.getRootPane().addComponentListener(new ComponentAdapter() {
            @Override
            public void componentResized(ComponentEvent e) {
                // This is only called when the user releases the mouse button.
                jScrollPane1.setPreferredSize(new Dimension(getSize().width-250,getSize().height-250));
                jTablePanel.setPreferredSize(new Dimension(getSize().width-250,getSize().height-250));
                jMainView.setSize(getSize());
                revalidate();
                repaint();
                
            }
        });
    }

    private void setWindowCenter(){
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        int framewidth = this.getSize().width;//get the width of the frame  
        int frameheight = this.getSize().height;
        int framelocationX = (dim.width - framewidth) / 2;
        int framelocationY = (dim.height - frameheight) / 2;
        this.setLocation(framelocationX, framelocationY);
    }
    
    private void setWindowTop(){
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        int framewidth = this.getSize().width;//get the width of the frame  
        int framelocationX = (dim.width - framewidth) / 2;
        this.setLocation(framelocationX, 0);
    }
    
    private JComboBox getYearInput(){
        String[] yearPossible = new String[100];
        yearPossible[0] = "YY";
        int currentYear = Calendar.getInstance().get(Calendar.YEAR);
        for (int i = 1; i < 100; i++) {
            yearPossible[i] = "" + (currentYear - i + 1);
        }
        JComboBox yearInput = new JComboBox(yearPossible); 
        ((JLabel)yearInput.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
        return yearInput;
    }
    
    private void initSearchPanels(){
        jObjectsSearchPanel.setLayout(new GridLayout(2,this.objectsFields.length));
        for(int i = 0; i < this.objectsFields.length; i++){
            JLabel newLabel = new JLabel(this.objectsFields[i]);
            newLabel.setHorizontalAlignment(SwingConstants.CENTER);
            this.jObjectsSearchPanel.add(newLabel);
        }
        for(int i = 0; i < this.objectsFields.length-1; i++) jObjectsSearchPanel.add(new JTextField());    
        jObjectsSearchPanel.add(getYearInput());
        jObjectsSearchPanel.setPreferredSize(objectsSearchDim);
        
       
        this.jServiceCallSearchPanel.setLayout(new GridLayout(3,this.serviceCallsFields.length));
        for(int i = 0; i < this.serviceCallsFields.length; i++){         
            JLabel newLabel = new JLabel(this.serviceCallsFields[i]);
            newLabel.setHorizontalAlignment(SwingConstants.CENTER);
            this.jServiceCallSearchPanel.add(newLabel);    
        }
        
        for(int i = 0; i < this.serviceCallsFields.length; i++){
             if(this.serviceCallsFields[i].equals("Date")) jServiceCallSearchPanel.add(prepareDateSelectPanel());
             else jServiceCallSearchPanel.add(new JTextField());
        }
        
        for(int i = 0; i < this.serviceCallsFields.length; i++){
            jServiceCallSearchPanel.add(new JPanel());
        }
       
    }
    
    private JPanel prepareDateSelectPanel(){
        JPanel datePanel = new JPanel(new GridBagLayout());
       GridBagConstraints c = new GridBagConstraints();
       c.fill = GridBagConstraints.HORIZONTAL; 
       
        String[] day = new String[32];
        day[0] = "DD";
        for(int i = 1; i < 32; i++) day[i] = "" + i;
        
        String[] month = new String[13];
        month[0] = "MM";
        for(int i = 1; i < 13; i++) month[i] = ""+i;
        
        JComboBox dayInput = new JComboBox(day); 
        ((JLabel)dayInput.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
        
        JComboBox monthInput = new JComboBox(month); 
        ((JLabel)monthInput.getRenderer()).setHorizontalAlignment(SwingConstants.CENTER);
       
        c.weightx = 0.2;
        c.gridx = 0;
        c.gridy = 0;
        datePanel.add(dayInput,c);
        c.weightx = 0.2;
        c.gridx = 1;
        datePanel.add(monthInput,c);
        JComboBox yearInput = getYearInput();
        c.weightx = 0.6;
        c.gridx = 2;
        datePanel.add(yearInput,c);
        
        dayInput.addActionListener(new DatePickerEventListener());
        monthInput.addActionListener(new DatePickerEventListener());
        yearInput.addActionListener(new DatePickerEventListener());
        
        return datePanel;
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFileChooser = new javax.swing.JFileChooser();
        jLogin = new javax.swing.JPanel(new FlowLayout(FlowLayout.CENTER));
        jLoginLabel = new javax.swing.JPanel(new FlowLayout(FlowLayout.CENTER));
        jLabel4 = new javax.swing.JLabel();
        jLoginInputs = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jUsernameField = new javax.swing.JTextField();
        jPasswordField = new javax.swing.JPasswordField();
        jloginButtons = new javax.swing.JPanel(new FlowLayout(FlowLayout.CENTER));
        jLoginButton = new javax.swing.JButton();
        jExitButton = new javax.swing.JButton();
        huismanLabel = new javax.swing.JLabel(new ImageIcon(System.getProperty("user.dir")+"\\huisman_login.jpg"));
        jMainView = new javax.swing.JPanel();
        jTablePanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable = new javax.swing.JTable(){
            @Override
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };
        jUserButtonPanel = new javax.swing.JPanel();
        jNewUser = new javax.swing.JButton();
        jDeleteUser = new javax.swing.JButton();
        jUpdateUser = new javax.swing.JButton();
        jObjectButtonPanel = new javax.swing.JPanel();
        jNewObject = new javax.swing.JButton();
        jDeleteObject = new javax.swing.JButton();
        jObjectAddServiceCall = new javax.swing.JButton();
        jViewServiceCalls = new javax.swing.JButton();
        jGenerateServiceReport = new javax.swing.JButton();
        jServiceCallButtonPanel = new javax.swing.JPanel();
        jNewServiceCall = new javax.swing.JButton();
        jDeleteServiceCall = new javax.swing.JButton();
        jViewServiceCallObject = new javax.swing.JButton();
        jGetReport = new javax.swing.JButton();
        jOpenReportFolder = new javax.swing.JButton();
        jApproveButtonPanel = new javax.swing.JPanel();
        jApprove = new javax.swing.JButton();
        jReject = new javax.swing.JButton();
        jRefresh = new javax.swing.JButton();
        jObjectsSearchPanel = new javax.swing.JPanel();
        jSearchServiceCallButtonPanel = new javax.swing.JPanel();
        jSearchServiceCallButton = new javax.swing.JButton();
        jPrint = new javax.swing.JButton();
        jSearchObjectsButtonPanel = new javax.swing.JPanel();
        jSearchObjectsButton = new javax.swing.JButton();
        jComplexPanel = new javax.swing.JPanel();
        jServiceCallSearchScrollPanel = new javax.swing.JScrollPane();
        jServiceCallSearchPanel = new javax.swing.JPanel();
        jGeneralSearch = new javax.swing.JButton();
        jClearSearch = new javax.swing.JButton();
        jGeneralSearchTextField = new javax.swing.JTextField();
        jMenu = new javax.swing.JMenuBar();
        jAdminMenu = new javax.swing.JMenu();
        jManageUsers = new javax.swing.JMenuItem();
        jUploadReport = new javax.swing.JMenuItem();
        jSearchMenu = new javax.swing.JMenu();
        jSearchObjects = new javax.swing.JMenuItem();
        jSearchServiceCalls = new javax.swing.JMenuItem();
        jApproveMenu = new javax.swing.JMenu();
        jApproveObjects = new javax.swing.JMenuItem();
        jApproveServiceCalls = new javax.swing.JMenuItem();
        jAccountMenu = new javax.swing.JMenu();
        jLogout = new javax.swing.JMenuItem();
        jPassword = new javax.swing.JMenuItem();

        jFileChooser.setDialogTitle("Import File");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(this.loginDim);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("Service Record Database");

        javax.swing.GroupLayout jLoginLabelLayout = new javax.swing.GroupLayout(jLoginLabel);
        jLoginLabel.setLayout(jLoginLabelLayout);
        jLoginLabelLayout.setHorizontalGroup(
            jLoginLabelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLoginLabelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jLoginLabelLayout.setVerticalGroup(
            jLoginLabelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLoginLabelLayout.createSequentialGroup()
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 11, Short.MAX_VALUE))
        );

        jLabel3.setText("Password:");

        jLabel2.setText("User Name:");

        jPasswordField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jPasswordFieldKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jLoginInputsLayout = new javax.swing.GroupLayout(jLoginInputs);
        jLoginInputs.setLayout(jLoginInputsLayout);
        jLoginInputsLayout.setHorizontalGroup(
            jLoginInputsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jLoginInputsLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jLoginInputsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jLoginInputsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jUsernameField, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(41, 41, 41))
        );
        jLoginInputsLayout.setVerticalGroup(
            jLoginInputsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLoginInputsLayout.createSequentialGroup()
                .addContainerGap(15, Short.MAX_VALUE)
                .addGroup(jLoginInputsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jUsernameField, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jLoginInputsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jLoginButton.setText("Login");
        jLoginButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLoginButtonMouseReleased(evt);
            }
        });

        jExitButton.setText("Exit");
        jExitButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jExitButtonMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout jloginButtonsLayout = new javax.swing.GroupLayout(jloginButtons);
        jloginButtons.setLayout(jloginButtonsLayout);
        jloginButtonsLayout.setHorizontalGroup(
            jloginButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jloginButtonsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLoginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jExitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(108, 108, 108))
        );
        jloginButtonsLayout.setVerticalGroup(
            jloginButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jloginButtonsLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jloginButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLoginButton)
                    .addComponent(jExitButton))
                .addContainerGap())
        );

        huismanLabel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        javax.swing.GroupLayout jLoginLayout = new javax.swing.GroupLayout(jLogin);
        jLogin.setLayout(jLoginLayout);
        jLoginLayout.setHorizontalGroup(
            jLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLoginLayout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addGroup(jLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jLoginLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLoginInputs, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jloginButtons, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(huismanLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 325, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(578, Short.MAX_VALUE))
        );
        jLoginLayout.setVerticalGroup(
            jLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jLoginLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(huismanLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(40, 40, 40)
                .addComponent(jLoginLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLoginInputs, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addComponent(jloginButtons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(241, Short.MAX_VALUE))
        );

        huismanLabel.setLayout(new FlowLayout(FlowLayout.CENTER));

        getContentPane().add(jLogin, java.awt.BorderLayout.CENTER);

        jTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTableMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable);

        javax.swing.GroupLayout jTablePanelLayout = new javax.swing.GroupLayout(jTablePanel);
        jTablePanel.setLayout(jTablePanelLayout);
        jTablePanelLayout.setHorizontalGroup(
            jTablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 697, Short.MAX_VALUE)
        );
        jTablePanelLayout.setVerticalGroup(
            jTablePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 574, Short.MAX_VALUE)
        );

        jNewUser.setText("New User");
        jNewUser.setPreferredSize(new java.awt.Dimension(63, 23));
        jNewUser.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jNewUserMouseReleased(evt);
            }
        });

        jDeleteUser.setText("Delete User");
        jDeleteUser.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jDeleteUserMouseReleased(evt);
            }
        });

        jUpdateUser.setText("Update User");
        jUpdateUser.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jUpdateUserMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout jUserButtonPanelLayout = new javax.swing.GroupLayout(jUserButtonPanel);
        jUserButtonPanel.setLayout(jUserButtonPanelLayout);
        jUserButtonPanelLayout.setHorizontalGroup(
            jUserButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jUserButtonPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jUserButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jUpdateUser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jDeleteUser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jNewUser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jUserButtonPanelLayout.setVerticalGroup(
            jUserButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jUserButtonPanelLayout.createSequentialGroup()
                .addComponent(jNewUser, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jDeleteUser)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jUpdateUser)
                .addGap(0, 15, Short.MAX_VALUE))
        );

        jUserButtonPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jDeleteUser, jNewUser, jUpdateUser});

        jNewObject.setText("New Object");
        jNewObject.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jNewObjectMouseReleased(evt);
            }
        });

        jDeleteObject.setText("Delete Object");
        jDeleteObject.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jDeleteObjectMouseReleased(evt);
            }
        });

        jObjectAddServiceCall.setText("Add Service Call");
        jObjectAddServiceCall.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jObjectAddServiceCallMouseReleased(evt);
            }
        });

        jViewServiceCalls.setText("View Service Calls");
        jViewServiceCalls.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jViewServiceCallsMouseReleased(evt);
            }
        });

        jGenerateServiceReport.setText("Generate History Sheet");
        jGenerateServiceReport.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jGenerateServiceReportMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout jObjectButtonPanelLayout = new javax.swing.GroupLayout(jObjectButtonPanel);
        jObjectButtonPanel.setLayout(jObjectButtonPanelLayout);
        jObjectButtonPanelLayout.setHorizontalGroup(
            jObjectButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jObjectButtonPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jObjectButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jNewObject, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jDeleteObject, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jObjectAddServiceCall, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jViewServiceCalls, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jGenerateServiceReport, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jObjectButtonPanelLayout.setVerticalGroup(
            jObjectButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jObjectButtonPanelLayout.createSequentialGroup()
                .addComponent(jNewObject, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jDeleteObject)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jObjectAddServiceCall)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jViewServiceCalls)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jGenerateServiceReport)
                .addContainerGap(29, Short.MAX_VALUE))
        );

        jObjectButtonPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jDeleteObject, jGenerateServiceReport, jNewObject, jObjectAddServiceCall, jViewServiceCalls});

        jNewServiceCall.setText("New Service Call");
        jNewServiceCall.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jNewServiceCallMouseReleased(evt);
            }
        });

        jDeleteServiceCall.setText("Delete Service Call");
        jDeleteServiceCall.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jDeleteServiceCallMouseReleased(evt);
            }
        });

        jViewServiceCallObject.setText("View Object");
        jViewServiceCallObject.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jViewServiceCallObjectMouseReleased(evt);
            }
        });

        jGetReport.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jGetReport.setText("Get Service Report");
        jGetReport.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jGetReportMouseReleased(evt);
            }
        });

        jOpenReportFolder.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jOpenReportFolder.setText("Open Report Folder");
        jOpenReportFolder.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jOpenReportFolderMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout jServiceCallButtonPanelLayout = new javax.swing.GroupLayout(jServiceCallButtonPanel);
        jServiceCallButtonPanel.setLayout(jServiceCallButtonPanelLayout);
        jServiceCallButtonPanelLayout.setHorizontalGroup(
            jServiceCallButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jServiceCallButtonPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jServiceCallButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jNewServiceCall, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jDeleteServiceCall, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jViewServiceCallObject, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jGetReport, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jOpenReportFolder, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jServiceCallButtonPanelLayout.setVerticalGroup(
            jServiceCallButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jServiceCallButtonPanelLayout.createSequentialGroup()
                .addComponent(jNewServiceCall, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jDeleteServiceCall)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jViewServiceCallObject)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jGetReport)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jOpenReportFolder)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jServiceCallButtonPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jDeleteServiceCall, jGetReport, jNewServiceCall, jViewServiceCallObject});

        jApprove.setText("Approve");
        jApprove.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jApproveMouseReleased(evt);
            }
        });

        jReject.setText("Reject");
        jReject.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jRejectMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout jApproveButtonPanelLayout = new javax.swing.GroupLayout(jApproveButtonPanel);
        jApproveButtonPanel.setLayout(jApproveButtonPanelLayout);
        jApproveButtonPanelLayout.setHorizontalGroup(
            jApproveButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jApproveButtonPanelLayout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(jApproveButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jReject, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jApprove, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE))
                .addGap(0, 11, Short.MAX_VALUE))
        );
        jApproveButtonPanelLayout.setVerticalGroup(
            jApproveButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jApproveButtonPanelLayout.createSequentialGroup()
                .addComponent(jApprove, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jReject)
                .addContainerGap(23, Short.MAX_VALUE))
        );

        jApproveButtonPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jApprove, jReject});

        jRefresh.setText("Refresh");
        jRefresh.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jRefreshMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout jObjectsSearchPanelLayout = new javax.swing.GroupLayout(jObjectsSearchPanel);
        jObjectsSearchPanel.setLayout(jObjectsSearchPanelLayout);
        jObjectsSearchPanelLayout.setHorizontalGroup(
            jObjectsSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 243, Short.MAX_VALUE)
        );
        jObjectsSearchPanelLayout.setVerticalGroup(
            jObjectsSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jSearchServiceCallButton.setText("Search");
        jSearchServiceCallButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jSearchServiceCallButtonMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout jSearchServiceCallButtonPanelLayout = new javax.swing.GroupLayout(jSearchServiceCallButtonPanel);
        jSearchServiceCallButtonPanel.setLayout(jSearchServiceCallButtonPanelLayout);
        jSearchServiceCallButtonPanelLayout.setHorizontalGroup(
            jSearchServiceCallButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jSearchServiceCallButtonPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSearchServiceCallButton)
                .addContainerGap(53, Short.MAX_VALUE))
        );
        jSearchServiceCallButtonPanelLayout.setVerticalGroup(
            jSearchServiceCallButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jSearchServiceCallButtonPanelLayout.createSequentialGroup()
                .addContainerGap(23, Short.MAX_VALUE)
                .addComponent(jSearchServiceCallButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19))
        );

        jPrint.setText("Export to Excel");
        jPrint.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jPrintMouseReleased(evt);
            }
        });

        jSearchObjectsButton.setText("Search");
        jSearchObjectsButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jSearchObjectsButtonMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout jSearchObjectsButtonPanelLayout = new javax.swing.GroupLayout(jSearchObjectsButtonPanel);
        jSearchObjectsButtonPanel.setLayout(jSearchObjectsButtonPanelLayout);
        jSearchObjectsButtonPanelLayout.setHorizontalGroup(
            jSearchObjectsButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jSearchObjectsButtonPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSearchObjectsButton)
                .addContainerGap(43, Short.MAX_VALUE))
        );
        jSearchObjectsButtonPanelLayout.setVerticalGroup(
            jSearchObjectsButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jSearchObjectsButtonPanelLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jSearchObjectsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jServiceCallSearchScrollPanel.setBorder(null);
        jServiceCallSearchScrollPanel.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        javax.swing.GroupLayout jServiceCallSearchPanelLayout = new javax.swing.GroupLayout(jServiceCallSearchPanel);
        jServiceCallSearchPanel.setLayout(jServiceCallSearchPanelLayout);
        jServiceCallSearchPanelLayout.setHorizontalGroup(
            jServiceCallSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 298, Short.MAX_VALUE)
        );
        jServiceCallSearchPanelLayout.setVerticalGroup(
            jServiceCallSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        jServiceCallSearchScrollPanel.setViewportView(jServiceCallSearchPanel);

        javax.swing.GroupLayout jComplexPanelLayout = new javax.swing.GroupLayout(jComplexPanel);
        jComplexPanel.setLayout(jComplexPanelLayout);
        jComplexPanelLayout.setHorizontalGroup(
            jComplexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jComplexPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jServiceCallSearchScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)
                .addContainerGap())
        );
        jComplexPanelLayout.setVerticalGroup(
            jComplexPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jServiceCallSearchScrollPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );

        jGeneralSearch.setText("General Search");
        jGeneralSearch.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jGeneralSearchMouseReleased(evt);
            }
        });

        jClearSearch.setText("Clear Search");
        jClearSearch.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jClearSearchMouseReleased(evt);
            }
        });

        javax.swing.GroupLayout jMainViewLayout = new javax.swing.GroupLayout(jMainView);
        jMainView.setLayout(jMainViewLayout);
        jMainViewLayout.setHorizontalGroup(
            jMainViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jMainViewLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jMainViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jObjectButtonPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jServiceCallButtonPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jApproveButtonPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jUserButtonPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jMainViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jMainViewLayout.createSequentialGroup()
                        .addComponent(jGeneralSearchTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(jGeneralSearch)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPrint)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jClearSearch)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRefresh))
                    .addGroup(jMainViewLayout.createSequentialGroup()
                        .addComponent(jObjectsSearchPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSearchObjectsButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComplexPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSearchServiceCallButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jTablePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(51, Short.MAX_VALUE))
        );

        jMainViewLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jPrint, jRefresh});

        jMainViewLayout.setVerticalGroup(
            jMainViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jMainViewLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jMainViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jSearchServiceCallButtonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jComplexPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jSearchObjectsButtonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jObjectsSearchPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jMainViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jMainViewLayout.createSequentialGroup()
                        .addComponent(jUserButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jObjectButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jServiceCallButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jApproveButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jMainViewLayout.createSequentialGroup()
                        .addComponent(jTablePanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jMainViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jRefresh)
                            .addComponent(jGeneralSearch)
                            .addComponent(jPrint)
                            .addComponent(jClearSearch)
                            .addComponent(jGeneralSearchTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(8, 8, 8))
        );

        jMainViewLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jClearSearch, jGeneralSearch, jGeneralSearchTextField, jPrint, jRefresh});

        getContentPane().add(jMainView, java.awt.BorderLayout.PAGE_START);

        jMenu.setPreferredSize(new java.awt.Dimension(800,30));

        jAdminMenu.setText("Admin");
        jAdminMenu.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jAdminMenu.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jAdminMenu.setPreferredSize(new java.awt.Dimension(60, 15));

        jManageUsers.setText("Manage Users");
        jManageUsers.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jManageUsersMouseReleased(evt);
            }
        });
        jAdminMenu.add(jManageUsers);

        jUploadReport.setText("Upload History Sheet");
        jUploadReport.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jUploadReportMouseReleased(evt);
            }
        });
        jAdminMenu.add(jUploadReport);

        jMenu.add(jAdminMenu);

        jSearchMenu.setText("Search");
        jSearchMenu.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jSearchMenu.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jSearchMenu.setPreferredSize(new java.awt.Dimension(60, 15));

        jSearchObjects.setText("Objects");
        jSearchObjects.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jSearchObjectsMouseReleased(evt);
            }
        });
        jSearchMenu.add(jSearchObjects);

        jSearchServiceCalls.setText("Service Calls");
        jSearchServiceCalls.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jSearchServiceCallsMouseReleased(evt);
            }
        });
        jSearchMenu.add(jSearchServiceCalls);

        jMenu.add(jSearchMenu);

        jApproveMenu.setText("Approve");
        jApproveMenu.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jApproveMenu.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jApproveMenu.setPreferredSize(new java.awt.Dimension(70, 15));

        jApproveObjects.setText("Objects");
        jApproveObjects.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jApproveObjectsMouseReleased(evt);
            }
        });
        jApproveMenu.add(jApproveObjects);

        jApproveServiceCalls.setText("Service Calls");
        jApproveServiceCalls.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jApproveServiceCallsMouseReleased(evt);
            }
        });
        jApproveMenu.add(jApproveServiceCalls);

        jMenu.add(jApproveMenu);

        jAccountMenu.setText("Account");

        jLogout.setText("Logout");
        jLogout.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jLogoutMouseReleased(evt);
            }
        });
        jAccountMenu.add(jLogout);

        jPassword.setText("Password");
        jPassword.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jPasswordMouseReleased(evt);
            }
        });
        jAccountMenu.add(jPassword);

        jMenu.add(jAccountMenu);

        setJMenuBar(jMenu);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jPasswordMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPasswordMouseReleased
        // TODO add your handling code here:
        ArrayList<String> passLabel = new ArrayList<>();
        passLabel.add("old password:");
        passLabel.add("new password:");
        passLabel.add("confirm password");
        JPanel passPanel = getInputBox(passLabel, true, null);

        int result = JOptionPane.showConfirmDialog(this, passPanel, "Change Your Password", JOptionPane.OK_CANCEL_OPTION);
        while (result == JOptionPane.OK_OPTION) {
            ArrayList<String> searchField = new ArrayList<>();
            ArrayList<String> constraintField = new ArrayList<>();
            ArrayList<String> constraintValues = new ArrayList<>();
            ArrayList<Integer> constraintType = new ArrayList<>();
            searchField.add("password");
            constraintField.add("Username");
            constraintValues.add(loginMsn.username);
            constraintType.add(new Integer(QueryMessage.STRING_TYPE));
            QueryMessage newQuery = new QueryMessage(QueryMessage.SEARCH, "persons", searchField,
                    constraintField, constraintValues, constraintType, null);
            newQuery = serverRountine(newQuery); if (newQuery == null) return;

            JPasswordField passField = (JPasswordField) passPanel.getComponent(1);
            if (newQuery.result.get(0).equals(passField.getText())) {
                JPasswordField newPassField = (JPasswordField) passPanel.getComponent(3);
                JPasswordField confirmField = (JPasswordField) passPanel.getComponent(5);
                if (newPassField.getText().equals(confirmField.getText())) {
                    String passwordMsn = PasswordVerifier.getPasswordErrorMsn(newPassField.getText());
                    if(passwordMsn != null){
                        JOptionPane.showMessageDialog(this, passwordMsn, "Error", JOptionPane.ERROR_MESSAGE);
                        result = JOptionPane.showConfirmDialog(this, passPanel, "Change Your Password", JOptionPane.OK_CANCEL_OPTION);
                        continue;
                    }
                    
                    ArrayList<String> updateFields = new ArrayList<>();
                    ArrayList<String> updateValues = new ArrayList<>();
                    ArrayList<Integer> updateType = new ArrayList<>();
                    updateFields.add("password");
                    updateValues.add(newPassField.getText());
                    updateType.add(new Integer(QueryMessage.STRING_TYPE));
                    newQuery = new QueryMessage(QueryMessage.UPDATE, "persons", updateFields,
                            updateValues, updateType, constraintField, constraintValues, constraintType);
                    newQuery = serverRountine(newQuery); if (newQuery == null) return;
                    
                    if (newQuery.queryStatus != 0) {
                        JOptionPane.showMessageDialog(this, "Password update failure!\n " + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
                    } else {
                        JOptionPane.showConfirmDialog(this, "Updated Your Password", "Message", JOptionPane.PLAIN_MESSAGE);
                        break;
                    }

                } else {
                    JOptionPane.showMessageDialog(this, "New password and confirm password not match!\n ", "Error", JOptionPane.ERROR_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(this, "Old password wrong!\n ", "Error", JOptionPane.ERROR_MESSAGE);

            }
            result = JOptionPane.showConfirmDialog(this, passPanel, "Change Your Password", JOptionPane.OK_CANCEL_OPTION);
        }
    }//GEN-LAST:event_jPasswordMouseReleased

    private void jLogoutMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLogoutMouseReleased
        // TODO add your handling code here:
        QueryMessage terminateMsn = new QueryMessage();
        try {
            this.getOutStream().writeObject(terminateMsn);
        } catch (IOException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }
        logoutProcedure();
    }//GEN-LAST:event_jLogoutMouseReleased

    private void jLoginButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLoginButtonMouseReleased
        // TODO add your handling code here:
        loginProcedure();
    }//GEN-LAST:event_jLoginButtonMouseReleased

    private void jExitButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jExitButtonMouseReleased
        // TODO add your handling code here:
        System.exit(1);
    }//GEN-LAST:event_jExitButtonMouseReleased

    private void jManageUsersMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jManageUsersMouseReleased
        // TODO add your handling code here:
        String[] newFields = {"username", "security level"};
        ArrayList<String> outputFields = new ArrayList<>(Arrays.asList("username", "securitylevel"));
        QueryMessage newQuery = new QueryMessage(QueryMessage.SEARCH, "persons", outputFields, null, null, null, null);
        newQuery = serverRountine(newQuery); if (newQuery == null) return;

        if (newQuery.queryStatus == 0) {
            this.setAllfeaturesNotVisible();
            this.enableAllMenuItem();
            this.jManageUsers.setEnabled(false);
            this.jRefresh.setVisible(true);
            
            Object[][] data = new Object[newQuery.result.size() / 2][2];
            for (int i = 0; i < newQuery.result.size() / 2; i++) {
                data[i][0] = newQuery.result.get(2 * i);
                data[i][1] = SecurityLevel.getString(Integer.parseInt(newQuery.result.get(2 * i + 1)));
            }

            jTable.setModel(new DefaultTableModel(data, newFields));
            jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
           
            this.setHighlightTable(null);
            this.updateTableHeight();
            
            this.jTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
          
            this.jTable.setPreferredScrollableViewportSize(this.userTableDim);
            this.jTablePanel.setPreferredSize(this.userTableDim);

            this.jTablePanel.setVisible(true);
            this.jUserButtonPanel.setVisible(true);
            this.jPrint.setVisible(false);
            this.setSize(this.userManageViewDim);
            this.jMainView.setSize(this.userManageViewDim);

        } else {
            JOptionPane.showMessageDialog(this, "Query Error:" + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
        }

    }//GEN-LAST:event_jManageUsersMouseReleased

    private void jUploadReportMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jUploadReportMouseReleased
        // TODO add your handling code here:
        jFileChooser.setDialogTitle("Upload Report");
        int returnVal = jFileChooser.showOpenDialog(this);
        File file = null;
        boolean successful = false;
        while (returnVal == JFileChooser.APPROVE_OPTION) {
            file = jFileChooser.getSelectedFile();
            if (!file.getName().endsWith(".xls") && !file.getName().endsWith(".xlsx")) {
                JOptionPane.showMessageDialog(this, "File type should be .xlsx", "Error",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                long fileSize = file.length();
                BufferedInputStream fileStream = null;
                try {
                    fileStream = new BufferedInputStream(new FileInputStream(file));
                } catch (FileNotFoundException ex) {
                    JOptionPane.showMessageDialog(this, "File Error:" + ex.getMessage(), "Error",
                            JOptionPane.ERROR_MESSAGE);
                    returnVal = jFileChooser.showOpenDialog(this);
                    continue;
                }

                QueryMessage newQuery = new QueryMessage(QueryMessage.TRANSFER, "TABLE_NOT_IMPLEMENT", file.getName(), file.length());
                newQuery = serverRountine(newQuery); if (newQuery == null) return;
                if (newQuery.queryStatus != 0) {
                    JOptionPane.showMessageDialog(this, "Server Error:" + newQuery.message, "Error",
                            JOptionPane.ERROR_MESSAGE);
                    returnVal = jFileChooser.showOpenDialog(this);
                    continue;
                }
                
                byte[] buffer = new byte[(int) fileSize];
                try {
                    fileStream.read(buffer, 0, (int) fileSize);
                    fileStream.close();
                } catch (IOException ex) {
                    JOptionPane.showMessageDialog(this, "File reader error:" + newQuery.message, "Error",
                            JOptionPane.ERROR_MESSAGE);
                    returnVal = jFileChooser.showOpenDialog(this);
                    continue;
                }
                newQuery = serverRountine(buffer); if (newQuery == null) return;
                
                if(newQuery.queryStatus != 0){
                    if(newQuery.queryStatus != 7 && newQuery.queryStatus != 8){
                        JOptionPane.showMessageDialog(this, "Server Error:" + newQuery.message, "Error",
                            JOptionPane.ERROR_MESSAGE);
                        returnVal = jFileChooser.showOpenDialog(this);
                        continue;
                    }
                    int choice = 0;
                    if(newQuery.queryStatus == 7){
                        choice = JOptionPane.showConfirmDialog(this, "Object does not exist, do you want to create a new one and upload?", "Warning", JOptionPane.OK_CANCEL_OPTION);
                    }else if(newQuery.queryStatus == 8){
                        choice = JOptionPane.showConfirmDialog(this, "Object does exist but contents is different from the one in dataabse, do you want to overwrite and upload?", "Warning", JOptionPane.OK_CANCEL_OPTION);
                    }
                    if(choice == JOptionPane.OK_OPTION){
                        newQuery.queryType = QueryMessage.CONFIRM;
                        newQuery = serverRountine(newQuery); if (newQuery == null) return;
                        if(newQuery.queryStatus != 0){
                            JOptionPane.showMessageDialog(this, "Server Error:" + newQuery.message, "Error",
                                JOptionPane.ERROR_MESSAGE);
                            returnVal = jFileChooser.showOpenDialog(this);
                            continue;
                        }
                    }
                    else{
                        newQuery.queryType = QueryMessage.CANCEL;
                        newQuery = serverRountine(newQuery); 
                        if (newQuery == null) return;
                        break;
                    }
                    
                }
                successful = true;
                break;
            }
            returnVal = jFileChooser.showOpenDialog(this);
        }
        if (successful) {
            JOptionPane.showConfirmDialog(this, "File Transfer Complete!", "Message", JOptionPane.PLAIN_MESSAGE);
        }
    }//GEN-LAST:event_jUploadReportMouseReleased

    private void jNewUserMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jNewUserMouseReleased
        // TODO add your handling code here:
        ArrayList<String> passLabel = new ArrayList<>();
        passLabel.add("Username: ");
        passLabel.add("Temperory Password: ");
        passLabel.add("Security Level: ");
        

        ArrayList<Component> content = new ArrayList<>();

        JList securityList = new JList(securityOptions);
        securityList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        securityList.setSelectedIndex(securityOptions.length-1);
        securityList.setCellRenderer(new DefaultListCellRenderer() {
            public int getHorizontalAlignment() {
                return CENTER;
            }
        });
        JTextArea userNameArea = new JTextArea();
        JTextArea passwordArea = new JTextArea();
        content.add(userNameArea);
        content.add(passwordArea);
        content.add(securityList);
        
        JPanel newUserPanel = getInputBox(passLabel, false, content);
        int result = JOptionPane.showConfirmDialog(this, newUserPanel, "Add New User", JOptionPane.OK_CANCEL_OPTION);
       
        boolean updated = false;
        while(result == JOptionPane.OK_OPTION){
            String userName = userNameArea.getText().trim();
            String password = passwordArea.getText().trim();
            if(userName.isEmpty() || password.isEmpty())
                JOptionPane.showMessageDialog(this, "Fields cannot be empty\n ", "Error", JOptionPane.ERROR_MESSAGE);
            else{
                String passwordMsn = PasswordVerifier.getPasswordErrorMsn(password);
                if(passwordMsn != null){
                    JOptionPane.showMessageDialog(this, passwordMsn, "Error", JOptionPane.ERROR_MESSAGE);
                    result = JOptionPane.showConfirmDialog(this, newUserPanel, "Add New User", JOptionPane.OK_CANCEL_OPTION);
                    continue;
                }
                
                QueryMessage newQuery;
                ArrayList<String> outputFields = new ArrayList<>(Arrays.asList("username"));
                ArrayList<String> constraintFields = new ArrayList<>(Arrays.asList("username"));
                ArrayList<String> constraintValues = new ArrayList<>(Arrays.asList(userName));
                ArrayList<Integer> constraintType = new ArrayList<>(Arrays.asList(QueryMessage.STRING_TYPE));
                newQuery = new QueryMessage(QueryMessage.SEARCH,"persons",outputFields,constraintFields,
                        constraintValues,constraintType,null);
                newQuery = serverRountine(newQuery); if (newQuery == null) return;
                
                if (newQuery.queryStatus == 0) {
                    if(!newQuery.result.isEmpty()){
                         JOptionPane.showMessageDialog(this, "User Existed!:", "Error", JOptionPane.ERROR_MESSAGE);
                    }else{
                        String securityCode = "" + securityList.getSelectedIndex();
                        ArrayList<String> updateValues = new ArrayList<>(Arrays.asList(userName,password,securityCode));
                        ArrayList<Integer> updateType = 
                                new ArrayList<>(Arrays.asList(QueryMessage.STRING_TYPE,QueryMessage.STRING_TYPE,QueryMessage.INT_TYPE));
                        newQuery = new QueryMessage(QueryMessage.INSERT,"persons",updateValues,updateType);
                        newQuery = serverRountine(newQuery); if (newQuery == null) return;
                        
                        if (newQuery.queryStatus != 0) {
                            JOptionPane.showMessageDialog(this, "Fail to add new user!\n " + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
                        } else {
                            JOptionPane.showConfirmDialog(this, "New user added!", "Message", JOptionPane.PLAIN_MESSAGE);
                            updated = true;
                            break;
                        }   
                    }   
                }else {
                    JOptionPane.showMessageDialog(this, "Query Error:" + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
                }
            }
            result = JOptionPane.showConfirmDialog(this, newUserPanel, "Add New User", JOptionPane.OK_CANCEL_OPTION);
        }
        if(updated) jRefreshMouseReleased(null);
    }//GEN-LAST:event_jNewUserMouseReleased

    private void jSearchObjectsMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jSearchObjectsMouseReleased
        // TODO add your handling code here:
        setupObjectTableAndSearch();
        this.jSearchObjects.setEnabled(false);
        this.jObjectButtonPanel.setVisible(true);
        this.setSize(this.objectViewDim);
        this.jMainView.setSize(this.objectViewDim);
        setWindowTop();
        this.jSearchObjectsButtonMouseReleased(evt);
    }//GEN-LAST:event_jSearchObjectsMouseReleased

    private void jRefreshMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRefreshMouseReleased
        // TODO add your handling code here:
        if(!this.jManageUsers.isEnabled()){
            jManageUsersMouseReleased(null);
        }else if(!this.jSearchObjects.isEnabled()){
            this.jSearchObjectsButtonMouseReleased(null);
        }else if(!this.jApproveObjects.isEnabled()){
            this.jSearchObjectsButtonMouseReleased(null);
        }else if(!this.jApproveServiceCalls.isEnabled()){
            this.jSearchServiceCallButtonMouseReleased(null);
        }else if(!this.jSearchServiceCalls.isEnabled()){
            this.jSearchServiceCallButtonMouseReleased(null);
        }
    }//GEN-LAST:event_jRefreshMouseReleased

    private void jDeleteUserMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jDeleteUserMouseReleased
        // TODO add your handling code here:
        if(jTable.getSelectedRow() == -1){
            JOptionPane.showMessageDialog(this, "Please select a user!"," Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        String username = (String)jTable.getValueAt(jTable.getSelectedRow(),0);
        ArrayList<String> constraintFields = new ArrayList<>(Arrays.asList("username"));
        ArrayList<String> constraintValues = new ArrayList<>(Arrays.asList(username));
        ArrayList<Integer> constraintType = new ArrayList<>(Arrays.asList(QueryMessage.STRING_TYPE));
        QueryMessage newQuery = new QueryMessage(QueryMessage.DELETE,"persons",null,
                constraintFields,constraintValues,constraintType,null);
        newQuery = serverRountine(newQuery); if (newQuery == null) return;
        
        if (newQuery.queryStatus != 0) {
            JOptionPane.showMessageDialog(this, "Fail to delete user!\n " + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showConfirmDialog(this, "User: "+username+" deleted!", "Message", JOptionPane.PLAIN_MESSAGE);
            jRefreshMouseReleased(null);
        }
    }//GEN-LAST:event_jDeleteUserMouseReleased

    private void jUpdateUserMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jUpdateUserMouseReleased
        // TODO add your handling code here:
         if(jTable.getSelectedRow() == -1){
            JOptionPane.showMessageDialog(this, "Please select a user!"," Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        String username = (String)jTable.getValueAt(jTable.getSelectedRow(),0);
        JComboBox securityBox = new JComboBox(securityOptions);
        securityBox.setSelectedIndex(securityOptions.length-1);
        int result = JOptionPane.showConfirmDialog(this,securityBox,"Change a security level", JOptionPane.OK_CANCEL_OPTION);
        
        if(result != JOptionPane.OK_OPTION) return;
        
        String securityCode = "" + securityBox.getSelectedIndex();
        ArrayList<String> updateFields = new ArrayList<>(Arrays.asList("securitylevel"));
        ArrayList<String> updateValues = new ArrayList<>(Arrays.asList(securityCode));
        ArrayList<Integer> updateType  = new ArrayList<>(Arrays.asList(QueryMessage.INT_TYPE));
        ArrayList<String> constraintFields = new ArrayList<>(Arrays.asList("username"));
        ArrayList<String> constraintValues = new ArrayList<>(Arrays.asList(username));
        ArrayList<Integer> constraintType = new ArrayList<>(Arrays.asList(QueryMessage.STRING_TYPE));
        QueryMessage newQuery = new QueryMessage(QueryMessage.UPDATE,"persons",updateFields,
                updateValues,updateType,constraintFields,constraintValues,constraintType);
        newQuery = serverRountine(newQuery); if (newQuery == null) return;
        
        if (newQuery.queryStatus != 0) {
            JOptionPane.showMessageDialog(this, "Fail to update user!\n " + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showConfirmDialog(this, "User: "+username+" updated!", "Message", JOptionPane.PLAIN_MESSAGE);
            jRefreshMouseReleased(null);
        }
    }//GEN-LAST:event_jUpdateUserMouseReleased

    private void jNewObjectMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jNewObjectMouseReleased
        // TODO add your handling code here:
        if(!this.jNewObject.isEnabled()) return;
        ArrayList<String> passLabel = new ArrayList<>(Arrays.asList(this.objectsFields));
        ArrayList<Component> content = new ArrayList<>();
        JTextArea[] inputArea = new JTextArea[this.objectsFields.length-1];
        
        for (int i = 0; i < this.objectsFields.length-1; i++) {
            inputArea[i] = new JTextArea();
            content.add(inputArea[i]);
        }
        JComboBox yearInput = this.getYearInput();
        content.add(yearInput);

        JPanel newObjectPanel = getInputBox(passLabel, false, content);
        int result = JOptionPane.showConfirmDialog(this, newObjectPanel, "Add a New Object", JOptionPane.OK_CANCEL_OPTION);

        while (result == JOptionPane.OK_OPTION) {
            String objectName = inputArea[0].getText().trim();
            String orderNumber = inputArea[1].getText().trim();
            if (objectName.isEmpty() || orderNumber.isEmpty()) {
                JOptionPane.showMessageDialog(this, "Object or Ordernumber feild cannot be empty\n ", "Error", JOptionPane.ERROR_MESSAGE);
            } else {
                QueryMessage newQuery;      
                String[] inputs = new String[this.objectsFields.length];
                for (int i = 0; i < this.objectsFields.length - 1; i++) {
                    inputs[i] = inputArea[i].getText().trim();
                }
                if (yearInput.getSelectedItem().equals("YY")) {
                    inputs[this.objectsFields.length - 1] = "";
                } else {
                    inputs[this.objectsFields.length - 1] = "" + yearInput.getSelectedItem();
                }
                ArrayList<String> updateValues = new ArrayList<>(Arrays.asList(inputs));
                ArrayList<Integer> updateType = new ArrayList<>(Arrays.asList(this.objectsFieldsType));
                newQuery = new QueryMessage(QueryMessage.INSERT, "objectspending", updateValues, updateType);

                newQuery = serverRountine(newQuery);
                if (newQuery == null) return;

                if (newQuery.queryStatus != 0) {
                    JOptionPane.showMessageDialog(this, "Fail to add new objects!\n " + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
                } else {
                    JOptionPane.showConfirmDialog(this, "New object added!", "Message", JOptionPane.PLAIN_MESSAGE);
                    break;
                }
            }
            result = JOptionPane.showConfirmDialog(this, newObjectPanel, "Add New Object", JOptionPane.OK_CANCEL_OPTION);
        }
    }//GEN-LAST:event_jNewObjectMouseReleased

    private void jSearchObjectsButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jSearchObjectsButtonMouseReleased
        // TODO add your handling code here:
        String[] input = new String[this.objectsFields.length];
        for(int i = 0; i < this.objectsFields.length-1; i++) input[i] = (((JTextField)this.jObjectsSearchPanel.getComponent(i+this.objectsFields.length)).getText()).trim();
        String selectedYear = (String)(((JComboBox)this.jObjectsSearchPanel.getComponent(2*this.objectsFields.length-1)).getSelectedItem());
        input[this.objectsFields.length-1] = selectedYear.equals("YY") ? "" : selectedYear;
        ArrayList<String> outputFields = new ArrayList<>(Arrays.asList(this.objectsFields));
        ArrayList<String> constraintFields = new ArrayList<>();
        ArrayList<String> constraintValues = new ArrayList<>();
        ArrayList<Integer> constraintType = new ArrayList<>();
        ArrayList<Boolean> fuzzySearch = new ArrayList<>();
        
        for(int i = 0 ; i < this.objectsFields.length; i++){
            if(!input[i].isEmpty()){
                constraintFields.add(this.objectsFields[i]);
                constraintValues.add(input[i]);
                constraintType.add(this.objectsFieldsType[i]);
                fuzzySearch.add(true);
            }
        }
        String searchTable;
        if(!this.jSearchObjects.isEnabled()) searchTable = "objects";
        else searchTable = "objectspending";
        
        QueryMessage newQuery = new QueryMessage(QueryMessage.SEARCH, searchTable, outputFields, constraintFields,
                        constraintValues, constraintType, fuzzySearch);
        newQuery = serverRountine(newQuery); if (newQuery == null) return;
        
        if (newQuery.queryStatus == 0) {
            Object[][] data = null;
            if(newQuery.result.isEmpty()){
                JOptionPane.showMessageDialog(this, "No result matched your search", "Empty", JOptionPane.INFORMATION_MESSAGE);
            }else{
                data = new Object[newQuery.result.size() / this.objectsFields.length][this.objectsFields.length];
                for(int i = 0; i < newQuery.result.size() / this.objectsFields.length; i++)
                    for(int j = 0; j < this.objectsFields.length; j++)
                        data[i][j] = newQuery.result.get(i*this.objectsFields.length+j);       
                
            }
           
            jTable.setModel(new DefaultTableModel(data, this.objectsFields));
            input[this.objectsFields.length-1] = "";
            this.setHighlightTable(input);
            this.updateTableHeight();
            
        } else {
            JOptionPane.showMessageDialog(this, "Query Error:" + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jSearchObjectsButtonMouseReleased

    private void jDeleteObjectMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jDeleteObjectMouseReleased
        // TODO add your handling code here:
        if(!this.jDeleteObject.isEnabled()) return;
        if(jTable.getSelectedRow() == -1){
            JOptionPane.showMessageDialog(this, "Please select a object!"," Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        
        String order_name = (String)jTable.getValueAt(jTable.getSelectedRow(),0);
        String msn =  this.jApproveObjects.isEnabled() ? "Are you sure to delete object:" + order_name + " and all its service calls?" : "Are you sure to reject object: " + order_name;
        int result = JOptionPane.showConfirmDialog(this,msn,"Deleting a object", JOptionPane.OK_CANCEL_OPTION);
        if(result != JOptionPane.OK_OPTION) return;
        
        ArrayList<String> constraintFields = new ArrayList<>(Arrays.asList("object"));
        ArrayList<String> constraintValues = new ArrayList<>(Arrays.asList(order_name));
        ArrayList<Integer> constraintType = new ArrayList<>(Arrays.asList(QueryMessage.STRING_TYPE));
        String tableName = this.jApproveObjects.isEnabled() ? "objects" : "objectspending";
        QueryMessage newQuery = new QueryMessage(QueryMessage.DELETE,tableName,null,
                constraintFields,constraintValues,constraintType,null);
        newQuery = serverRountine(newQuery); if (newQuery == null) return;
        
        if (newQuery.queryStatus != 0) {
            msn = this.jApproveObjects.isEnabled() ?  "Fail to delete the object!\n " :  "Fail to reject the object\n";
            JOptionPane.showMessageDialog(this,msn + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showConfirmDialog(this, "Object: "+order_name+" deleted!", "Message", JOptionPane.PLAIN_MESSAGE);
            jRefreshMouseReleased(null);
        }
    }//GEN-LAST:event_jDeleteObjectMouseReleased

    private void jApproveObjectsMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jApproveObjectsMouseReleased
        // TODO add your handling code here:
        setupObjectTableAndSearch();
        this.jApproveObjects.setEnabled(false);
        this.jApproveButtonPanel.setVisible(true);
        this.setSize(this.objectViewDim);
        this.jMainView.setSize(this.objectViewDim);
        setWindowTop();
        this.jSearchObjectsButtonMouseReleased(evt);
    }//GEN-LAST:event_jApproveObjectsMouseReleased

    private void jApproveMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jApproveMouseReleased
        // TODO add your handling code here:
        if(!this.jApprove.isEnabled()) return;
        int row = jTable.getSelectedRow();
        if(row == -1){
            JOptionPane.showMessageDialog(this, "Please select a term!"," Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        
        if (!this.jApproveObjects.isEnabled()) {
            ArrayList<String> updateValues = new ArrayList<>();
            ArrayList<Integer> updateType = new ArrayList<>(Arrays.asList(this.objectsFieldsType));
            for (int i = 0; i < this.objectsFields.length; i++) {
                String input = (String)jTable.getValueAt(row, i);
                if(input == null) 
                    input = "";
                updateValues.add(input);
            }
            QueryMessage newQuery = new QueryMessage(QueryMessage.INSERT, "objects", updateValues, updateType);
            newQuery = serverRountine(newQuery);
            if (newQuery == null) return;
            
            if (newQuery.queryStatus != 0) {
                JOptionPane.showMessageDialog(this, "Fail to approve the objects! Please check if the object has existed or not \n " + newQuery.message , "Error", JOptionPane.ERROR_MESSAGE);
                return;
            } else {
                ArrayList<String> constraintFields = new ArrayList<>();
                ArrayList<String> constraintValues = new ArrayList<>();
                ArrayList<Integer> constraintType = new ArrayList<>();
                for(int i = 0; i < this.objectsFields.length; i++){
                    if(!updateValues.get(i).isEmpty()){
                        constraintFields.add(this.objectsFields[i]);
                        constraintValues.add(updateValues.get(i));
                        constraintType.add(updateType.get(i));
                    }
                }
                newQuery = new QueryMessage(QueryMessage.DELETE,"objectspending",null,
                    constraintFields,constraintValues,constraintType,null);
                newQuery = serverRountine(newQuery); if (newQuery == null) return;
                if (newQuery.queryStatus != 0) {
                    JOptionPane.showMessageDialog(this, "Approve success but fail to delete object:  "+ updateValues.get(0) + " with error:" + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
                } else {
                    JOptionPane.showConfirmDialog(this, "Object: " + updateValues.get(0) + " approved!", "Message", JOptionPane.PLAIN_MESSAGE);
                    this.jRefreshMouseReleased(null);
                }
                
            }
            
        }
        else if(!this.jApproveServiceCalls.isEnabled()){
            ArrayList<String> updateValues = new ArrayList<>();
            ArrayList<Integer> updateType = new ArrayList<>(Arrays.asList(this.serviceCallsFieldsType));
            for (int i = 0; i < serviceCallsFields.length; i++) {
                String input = (String)jTable.getValueAt(row, i);
                if(input == null) 
                    input = "";
                updateValues.add(input);
            }
            QueryMessage newQuery = new QueryMessage(QueryMessage.INSERT, "servicerecords", updateValues, updateType);
            newQuery = serverRountine(newQuery);
            if (newQuery == null) return;
            
            if (newQuery.queryStatus != 0) {
                JOptionPane.showMessageDialog(this, "Fail to approve the service call! Please check if the object has existed or not \n " + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
                return;
            } else {
                ArrayList<String> constraintFields = new ArrayList<>();
                ArrayList<String> constraintValues = new ArrayList<>();
                ArrayList<Integer> constraintType = new ArrayList<>();
                for(int i = 0; i < serviceCallsFields.length; i++){
                    if(!updateValues.get(i).isEmpty()){
                        constraintFields.add(serviceCallsFields[i]);
                        constraintValues.add(updateValues.get(i));
                        constraintType.add(updateType.get(i));
                    }
                }
                newQuery = new QueryMessage(QueryMessage.DELETE,"servicerecordspending",null,
                    constraintFields,constraintValues,constraintType,null);
                newQuery = serverRountine(newQuery); if (newQuery == null) return;
                if (newQuery.queryStatus != 0) {
                    JOptionPane.showMessageDialog(this, "Approve success but fail to delete new service call:  "+ updateValues.get(1) + " with error:" + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
                } else {
                    JOptionPane.showConfirmDialog(this, "Service Call: " + updateValues.get(1) + " approved!", "Message", JOptionPane.PLAIN_MESSAGE);
                    this.jRefreshMouseReleased(null);
                }
                
            }
        }
    }//GEN-LAST:event_jApproveMouseReleased

    private void jPrintMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPrintMouseReleased
        // TODO add your handling code here:
        File file = null;
        String fileName = "ExportData";
        String fileExtension = ".xlsx";
        file = AllocateFile.GetFile(fileName, fileExtension, new File(this.tempDir));
        
        ExcelExporter exporter = null;
        ArrayList<ArrayList<String>> exportData = new ArrayList<>();
        if (!this.jSearchObjects.isEnabled() || !this.jApproveObjects.isEnabled()) {
            for (int i = 0; i < this.jTable.getRowCount(); i++) {
                exportData.add(new ArrayList<String>());
                for (int j = 0; j < ExcelFormat.objectsFields.length; j++) {
                    exportData.get(i).add((String) this.jTable.getValueAt(i, j));
                }
            }
            exporter = new ExcelExporter(exportData, null);
        } else if (!this.jSearchServiceCalls.isEnabled() || !this.jApproveServiceCalls.isEnabled()) {
            for (int i = 0; i < this.jTable.getRowCount(); i++) {
                exportData.add(new ArrayList<String>());
                for (int j = 0; j < ExcelFormat.serviceCallFields.length; j++) {
                    exportData.get(i).add((String) this.jTable.getValueAt(i, j));
                }
            }
            exporter = new ExcelExporter(null, exportData);
        }

        // export the contect to excel
        try {
            file.createNewFile();
            exporter.writeContents(file);
            Desktop.getDesktop().open(file);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "File Error" + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
           
        
    }//GEN-LAST:event_jPrintMouseReleased

    private void jSearchServiceCallsMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jSearchServiceCallsMouseReleased
        // TODO add your handling code here:
        setupServiceCallTableAndSearch();
        this.jSearchServiceCalls.setEnabled(false);
        this.jServiceCallButtonPanel.setVisible(true);
        this.setSize(this.mainViewDim);
        this.jMainView.setSize(this.mainViewDim);
        setWindowTop();
        //this.jSearchServiceCallButtonMouseReleased(evt);
    }//GEN-LAST:event_jSearchServiceCallsMouseReleased

    private void jApproveServiceCallsMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jApproveServiceCallsMouseReleased
        // TODO add your handling code here:
        setupServiceCallTableAndSearch();
        this.jApproveServiceCalls.setEnabled(false);
        this.jApproveButtonPanel.setVisible(true);
        this.setSize(this.mainViewDim);
        this.jMainView.setSize(this.mainViewDim);
        setWindowTop();
        //this.jSearchServiceCallButtonMouseReleased(evt);
    }//GEN-LAST:event_jApproveServiceCallsMouseReleased

    private void jSearchServiceCallButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jSearchServiceCallButtonMouseReleased
        // TODO add your handling code here:
        ArrayList<String> outputFields = new ArrayList<>(Arrays.asList(this.serviceCallsFields));
        ArrayList<String> constraintFields = new ArrayList<>();
        ArrayList<String> constraintValues = new ArrayList<>();
        ArrayList<Integer> constraintType = new ArrayList<>();
        ArrayList<Boolean> fuzzySearch = new ArrayList<>();
        String[] serachString = new String[this.serviceCallsFields.length];
        
        for(int i = 0; i < this.serviceCallsFields.length; i++){
            serachString[i] = "";
            if(this.serviceCallsFields[i].equals("Date")){
                JPanel datePickerPanel = (JPanel)this.jServiceCallSearchPanel.getComponent(this.serviceCallsFields.length+i);
                String[] date = new String[3];
                for(int j = 0; j < 3; j++)
                    date[j] = ((String)((JComboBox)datePickerPanel.getComponent(j)).getSelectedItem()).trim();
                if(!date[0].equals("DD")){
                    date[0] = date[0] + "/";
                    constraintFields.add("Date");
                    constraintValues.add(date[0]);
                }
                if(!date[1].equals("MM")){
                    date[1] = "/" + date[1] + "/";
                    constraintFields.add("Date");
                    constraintValues.add(date[1]);
                }
                if(!date[2].equals("YY")){
                    date[2] = "/" + date[2];
                    constraintFields.add("Date");
                    constraintValues.add(date[2]);
                }
            }else{
                JTextField input = (JTextField)this.jServiceCallSearchPanel.getComponent(this.serviceCallsFields.length+i);
                String searchInput = input.getText().trim();
                if(!searchInput.isEmpty()){
                    constraintFields.add(this.serviceCallsFields[i]);
                    constraintValues.add(searchInput);
                    serachString[i] = searchInput;
                }
            }
        }
        for(int i = 0; i < constraintFields.size(); i++){
            constraintType.add(QueryMessage.STRING_TYPE);
            fuzzySearch.add(true);
        }
        String searchTable;
        if(!this.jSearchServiceCalls.isEnabled()) searchTable = "ServiceRecords";
        else searchTable = "ServiceRecordsPending";
        
        QueryMessage newQuery = new QueryMessage(QueryMessage.SEARCH, searchTable, outputFields, constraintFields,
                        constraintValues, constraintType, fuzzySearch);
        newQuery = serverRountine(newQuery); if (newQuery == null) return;
        
        if (newQuery.queryStatus == 0) {
            Object[][] data = null;
            if(newQuery.result.isEmpty()){
                JOptionPane.showMessageDialog(this, "No result matched your search", "Empty", JOptionPane.INFORMATION_MESSAGE);
            }else{
                data = new Object[newQuery.result.size() / this.serviceCallsFields.length][serviceCallsFields.length];
                for(int i = 0; i < newQuery.result.size() / serviceCallsFields.length; i++)
                    for(int j = 0; j < serviceCallsFields.length; j++)
                        data[i][j] = newQuery.result.get(i*serviceCallsFields.length+j);       
                
            }
           
            jTable.setModel(new DefaultTableModel(data, serviceCallsFields));
            this.setHighlightTable(serachString);
            setupServiceCallDim();
            
            
        } else {
            JOptionPane.showMessageDialog(this, "Query Error:" + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jSearchServiceCallButtonMouseReleased

    private void jPasswordFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPasswordFieldKeyReleased
        // TODO add your handling code here:
        int key = evt.getKeyCode();
        if(key == KeyEvent.VK_ENTER){
            this.loginProcedure();
        }
    }//GEN-LAST:event_jPasswordFieldKeyReleased

    private void jNewServiceCallMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jNewServiceCallMouseReleased
        // TODO add your handling code here:
        if(!this.jNewServiceCall.isEnabled()) return;
        newServiceCall("");
    }//GEN-LAST:event_jNewServiceCallMouseReleased

    private void jDeleteServiceCallMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jDeleteServiceCallMouseReleased
        // TODO add your handling code here:
        if(!this.jDeleteServiceCall.isEnabled()) return;
        if(jTable.getSelectedRow() == -1){
            JOptionPane.showMessageDialog(this, "Please select a service call!"," Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        int selectedRow = jTable.getSelectedRow();
        
        String objectName = (String)jTable.getValueAt(selectedRow,0);
        String serivce_no = (String)jTable.getValueAt(selectedRow,1);
        int result = JOptionPane.showConfirmDialog(this,"Are you sure to delete service call: " + serivce_no + " under object: " + objectName,
                "Deleting a Object",JOptionPane.OK_CANCEL_OPTION);
        if(result != JOptionPane.OK_OPTION) return;
        
        ArrayList<String> constraintFields = new ArrayList<>();
        ArrayList<String> constraintValues = new ArrayList<>();
        ArrayList<Integer> constraintType = new ArrayList<>();
        for(int i = 0; i < this.serviceCallsFields.length; i++){
            String data = (String)jTable.getValueAt(selectedRow,i);
            if(data != null){
                constraintFields.add(this.serviceCallsFields[i]);
                constraintValues.add(data);
                constraintType.add(this.serviceCallsFieldsType[i]);
            }
        }
        
        String tableName = this.jApproveServiceCalls.isEnabled() ? "servicerecords" : "servicerecordspending";
        QueryMessage newQuery = new QueryMessage(QueryMessage.DELETE,tableName,null,
                constraintFields,constraintValues,constraintType,null);
        newQuery = serverRountine(newQuery); if (newQuery == null) return;
        
        if (newQuery.queryStatus != 0) {
            JOptionPane.showMessageDialog(this, "Fail to delete service call!\n " + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
        } else {
            JOptionPane.showConfirmDialog(this, "Service call: "+serivce_no+" deleted!", "Message", JOptionPane.PLAIN_MESSAGE);
            jRefreshMouseReleased(null);
        }
    }//GEN-LAST:event_jDeleteServiceCallMouseReleased

    private void jRejectMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jRejectMouseReleased
        // TODO add your handling code here:
        if(!this.jReject.isEnabled()) return;
        if(!this.jApproveObjects.isEnabled()){
            jDeleteObjectMouseReleased(null);
        }else if(!this.jApproveServiceCalls.isEnabled()){
            jDeleteServiceCallMouseReleased(null);
        }
    }//GEN-LAST:event_jRejectMouseReleased

    private void jTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableMouseClicked
        // TODO add your handling code here:
        switch(this.loginMsn.securitylevel){
            case SecurityLevel.ADMIN:
            case SecurityLevel.MANAGER:
                break;
            case SecurityLevel.COMMITOR:
            case SecurityLevel.VIEWER:
                return;
        }
        if(evt.getClickCount() == 2){
            if(!this.jSearchObjects.isEnabled() || !this.jApproveObjects.isEnabled())
                updateObjectFromTableSelection();
            if(!this.jSearchServiceCalls.isEnabled() || !this.jApproveServiceCalls.isEnabled())
                updateServiceCallFromTableSelection();
        }
    }//GEN-LAST:event_jTableMouseClicked

    private void jObjectAddServiceCallMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jObjectAddServiceCallMouseReleased
        // TODO add your handling code here:
        if(!this.jObjectAddServiceCall.isEnabled()) return;
        int row = jTable.getSelectedRow();
        if(row == -1){
            JOptionPane.showMessageDialog(this, "Please select a term!"," Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        String objectRef = (String)jTable.getValueAt(row, 0);
        newServiceCall(objectRef);
    }//GEN-LAST:event_jObjectAddServiceCallMouseReleased

    private void jViewServiceCallsMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jViewServiceCallsMouseReleased
        // TODO add your handling code here:
        int row = jTable.getSelectedRow();
        if(row == -1){
            JOptionPane.showMessageDialog(this, "Please select a term!"," Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        String objectRef = (String)jTable.getValueAt(row, 0);
        setupServiceCallTableAndSearch();
        ((JTextField)jServiceCallSearchPanel.getComponent(this.serviceCallsFields.length)).setText(objectRef);
        
        this.jSearchServiceCalls.setEnabled(false);
        this.jServiceCallButtonPanel.setVisible(true);
        this.setWindowTop();
        this.setSize(this.mainViewDim);
        this.jMainView.setSize(this.mainViewDim);
        jSearchServiceCallButtonMouseReleased(null);
        
    }//GEN-LAST:event_jViewServiceCallsMouseReleased

    private void jViewServiceCallObjectMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jViewServiceCallObjectMouseReleased
        // TODO add your handling code here:
        int row = jTable.getSelectedRow();
        if(row == -1){
            JOptionPane.showMessageDialog(this, "Please select a term!"," Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        String objectRef = (String)jTable.getValueAt(row, 0);
        setupObjectTableAndSearch();
        ((JTextField)jObjectsSearchPanel.getComponent(this.objectsFields.length)).setText(objectRef);
        
        this.jSearchObjects.setEnabled(false);
        this.jObjectButtonPanel.setVisible(true);
        jSearchObjectsButtonMouseReleased(null);
    }//GEN-LAST:event_jViewServiceCallObjectMouseReleased

    private void jGenerateServiceReportMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jGenerateServiceReportMouseReleased
        // TODO add your handling code here:
        int row = jTable.getSelectedRow();
        if(row == -1){
            JOptionPane.showMessageDialog(this, "Please select a object", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        String object = (String)jTable.getValueAt(row, 0);
        
        File file = null;
        boolean success = false;
        this.jFileChooser.setDialogTitle("Generate Report");
        this.jFileChooser.setSelectedFile(new File("Service History " + object +".xlsx"));
        int returnVal = this.jFileChooser.showSaveDialog(this);
        while(returnVal == JFileChooser.APPROVE_OPTION){
            File tempFile = jFileChooser.getSelectedFile();
            String fileName = tempFile.getAbsolutePath();
            if(!fileName.endsWith(".xlsx")) fileName += ".xlsx";
            file = new File(fileName);
            if(file.exists()){
                int value = JOptionPane.showConfirmDialog (this, "File existed, do you want to overwrite?", "Warning", JOptionPane.YES_NO_OPTION);
                if(value == JOptionPane.NO_OPTION){
                    returnVal = this.jFileChooser.showSaveDialog(this);
                    continue;
                }
            }
            
            BufferedOutputStream outStream;
            try {
                file.createNewFile();
                outStream = new BufferedOutputStream(new FileOutputStream(file));
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, "Cannot create the file:"+ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                returnVal = this.jFileChooser.showSaveDialog(this);
                continue;
            }
            
            QueryMessage newQuery = new QueryMessage(QueryMessage.GENERATE_REPOT,object,null,null);
            newQuery = serverRountine(newQuery); if(newQuery == null) return;
            if(newQuery.queryStatus != 0){
                JOptionPane.showMessageDialog(this, "Server Error:"+newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
                returnVal = this.jFileChooser.showSaveDialog(this);
                continue;
            }
            long fileLength = newQuery.fileLength;
            byte[] buffer;
            // write to file
            try {
                buffer = (byte[]) (this.getInputStream().readObject());
                outStream.write(buffer, 0, (int) fileLength);
                outStream.close();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this,"Server down!"+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                logoutProcedure();
                return;
            }
            
            newQuery.queryStatus = QueryMessage.CONFIRM;
            newQuery = serverRountine(newQuery); if(newQuery == null) return;
            if(newQuery.queryStatus != 0){
                JOptionPane.showMessageDialog(this,"Server error"+newQuery.message+" however file transfer complete!", "Error", JOptionPane.ERROR_MESSAGE);
            }
            success = true;
            break;
        }
        if(success){
            try {
                Desktop.getDesktop().open(file);
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this,"Cannot open the excel file:"+ex.getMessage(),"Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    }//GEN-LAST:event_jGenerateServiceReportMouseReleased

    private void jGetReportMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jGetReportMouseReleased
        // TODO add your handling code here:
        int row = jTable.getSelectedRow();
        if(row == -1){
            JOptionPane.showMessageDialog(this, "Please select a service call", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        int col = 0;
        for(int i = 0; i < this.serviceCallsFields.length;i++){
            if(this.serviceCallsFields[i].equalsIgnoreCase("service report")){
                col = i; break;
            }
        }
        String serverFileName = (String)jTable.getValueAt(row, col);
        if(serverFileName == null){
            JOptionPane.showMessageDialog(this, "Service call has no report", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        
        File file = null;
        String originalFileName = (new File(serverFileName)).getName();
        String fileNameWithoutExtension = FilenameUtils.removeExtension(originalFileName);
        String fileExtension = ".doc";
        file = AllocateFile.GetFile(fileNameWithoutExtension, fileExtension, new File(this.tempDir));
        
        BufferedOutputStream outStream;
        try {
            file.createNewFile();
            outStream = new BufferedOutputStream(new FileOutputStream(file));
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "Cannot create the file:" + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
            
        QueryMessage newQuery =
                new QueryMessage(QueryMessage.TRANSFER_BACK, "TABLE_NOT_IMPLEMENT", serverFileName, -1);

        newQuery = serverRountine(newQuery); if (newQuery == null) return;
        if (newQuery.queryStatus != 0) {
            JOptionPane.showMessageDialog(this, "Server Error:" + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        long fileLength = newQuery.fileLength;
        byte[] buffer;
        // write to file
        try {
            buffer = (byte[]) (this.getInputStream().readObject());
            outStream.write(buffer, 0, (int) fileLength);
            outStream.close();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Server down!" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            logoutProcedure();
            return;
        }
            
        newQuery.queryStatus = QueryMessage.CONFIRM;
        newQuery = serverRountine(newQuery); if (newQuery == null) return;
        
        if (newQuery.queryStatus != 0) {
            JOptionPane.showMessageDialog(this, "Server error" + newQuery.message + " however file transfer complete!", "Error", JOptionPane.ERROR_MESSAGE);
        }
        
        try {
            Desktop.getDesktop().open(file);
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "Cannot open the excel file:" + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        
    }//GEN-LAST:event_jGetReportMouseReleased

    private void jGeneralSearchMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jGeneralSearchMouseReleased
        // TODO add your handling code here:
        
        String keyword = this.jGeneralSearchTextField.getText().trim();
        if (keyword.isEmpty()) {
            JOptionPane.showMessageDialog(this, "Keyword cannot be empty!", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
            
        if(!this.jSearchObjects.isEnabled() || !this.jApproveObjects.isEnabled())
            generalSearchObjects(keyword);
        else if(!this.jSearchServiceCalls.isEnabled() || !this.jApproveServiceCalls.isEnabled())
            generalSearchServiceCalls(keyword);

    }//GEN-LAST:event_jGeneralSearchMouseReleased

    private void jClearSearchMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jClearSearchMouseReleased
        // TODO add your handling code here:
        // clear object fields input
        if(!this.jSearchObjects.isEnabled() || !this.jApproveObjects.isEnabled()){
            for(int i = 0; i < this.objectsFields.length-1; i++) ((JTextField)this.jObjectsSearchPanel.getComponent(i+this.objectsFields.length)).setText("");
            ((JComboBox)this.jObjectsSearchPanel.getComponent(2*this.objectsFields.length-1)).setSelectedIndex(0);
        }
        // clear search call fields input
        else if (!this.jSearchServiceCalls.isEnabled() || !this.jApproveServiceCalls.isEnabled()) {
            for (int i = 0; i < this.serviceCallsFields.length; i++) {
                if (this.serviceCallsFields[i].equals("Date")) {
                    JPanel datePickerPanel = (JPanel) this.jServiceCallSearchPanel.getComponent(this.serviceCallsFields.length + i);
                    for (int j = 0; j < 3; j++) 
                        ((JComboBox) datePickerPanel.getComponent(j)).setSelectedIndex(0);
                } else {
                    ((JTextField) this.jServiceCallSearchPanel.getComponent(this.serviceCallsFields.length + i)).setText("");
                }
            }
        }
        
        this.jGeneralSearchTextField.setText("");
    }//GEN-LAST:event_jClearSearchMouseReleased

    private void jOpenReportFolderMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jOpenReportFolderMouseReleased
        // TODO add your handling code here:
        int row = jTable.getSelectedRow();
        if(row == -1){
            JOptionPane.showMessageDialog(this, "Please select a service call", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        int col = 0;
        for(int i = 0; i < this.serviceCallsFields.length;i++){
            if(this.serviceCallsFields[i].equalsIgnoreCase("service report")){
                col = i; break;
            }
        }
        String serverFileName = (String)jTable.getValueAt(row, col);
        if(serverFileName == null){
            JOptionPane.showMessageDialog(this, "Service call has no report", "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
        File serverFileDir = new File(serverFileName);
        try {
            //Desktop.getDesktop().open(new File(serverFileDir.getParent()));
            Runtime.getRuntime().exec("explorer /select, " + serverFileDir.getParent());
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "Unable to open the report folder and error is: "+ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }
    }//GEN-LAST:event_jOpenReportFolderMouseReleased

    private void newServiceCall(String objectRef){
        ArrayList<String> passLabel = new ArrayList<>(Arrays.asList(this.serviceCallsFields));
        ArrayList<Component> content = new ArrayList<>();
        JPanel datePanel = this.prepareDateSelectPanel();
        for(int i = 0; i < this.serviceCallsFields.length; i++){
            if(this.serviceCallsFields[i].equals("Date")){
                content.add(datePanel);
            }
            else{
                JTextArea input = new JTextArea();
                content.add(input);
            }
        }
        ((JTextArea)content.get(0)).setText(objectRef);
        JPanel newServiceCallPanel = getInputBox(passLabel, false, content); 
        JScrollPane showPanel = new JScrollPane(newServiceCallPanel);
        showPanel.setPreferredSize(this.serviceCallInputDim);
        int result = JOptionPane.showConfirmDialog(this, showPanel, "Add a New Service Call", JOptionPane.OK_CANCEL_OPTION);
        
         while (result == JOptionPane.OK_OPTION) {
             String objectName = ((JTextArea)content.get(0)).getText().trim();
             String serviceCallNo = ((JTextArea)content.get(1)).getText().trim();
             if(objectName.isEmpty() || serviceCallNo.isEmpty())
                 JOptionPane.showMessageDialog(this, "Object or Service Call Number feild cannot be empty\n ", "Error", JOptionPane.ERROR_MESSAGE);
             else{
                 QueryMessage newQuery;
                 String[] inputs = new String[this.serviceCallsFields.length];
                 boolean valid = true;
                 for(int i = 0; i < this.serviceCallsFields.length; i++){
                     if(this.serviceCallsFields[i].equals("Date")){
                         String[] dateString = new String[3];
                         int emptyCount = 0;
                         for(int j = 0; j < 3; j++){
                             dateString[j] = (String)((JComboBox)datePanel.getComponent(j)).getSelectedItem();
                             if(dateString[j].equals("DD") || dateString[j].equals("MM") || dateString[j].equals("YY")){
                                 emptyCount++;
                             }
                         }
                         if(emptyCount == 3){
                             inputs[i] = "";
                             continue;
                         }
                         else if(emptyCount < 3 && emptyCount > 0){
                             valid = false;
                             break;
                         }
                         inputs[i]  = dateString[0] + "/" +dateString[1] + "/" +dateString[2];
                     }
                     else{
                         String textInput = ((JTextArea)content.get(i)).getText();
                         inputs[i] = textInput.trim();
                     }
                 }
                 if(!valid){
                     JOptionPane.showMessageDialog(this, "Date input is wrong", "Error", JOptionPane.ERROR_MESSAGE);
                     result = JOptionPane.showConfirmDialog(this, showPanel, "Add a Service Call", JOptionPane.OK_CANCEL_OPTION);
                     continue;
                 }
                 
                 ArrayList<String> updateValues = new ArrayList<>(Arrays.asList(inputs));
                 ArrayList<Integer> updateType = new ArrayList<>(Arrays.asList(this.serviceCallsFieldsType));
                 newQuery = new QueryMessage(QueryMessage.INSERT, "servicerecordspending", updateValues, updateType);
                 
                 newQuery = serverRountine(newQuery);
                if (newQuery == null) return;

                if (newQuery.queryStatus != 0) {
                    JOptionPane.showMessageDialog(this, "Fail to add new service call!\n " + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
                } else {
                    JOptionPane.showConfirmDialog(this, "New service call added!", "Message", JOptionPane.PLAIN_MESSAGE);
                    break;
                }
             }
             result = JOptionPane.showConfirmDialog(this, showPanel, "Add New Service Call", JOptionPane.OK_CANCEL_OPTION);   
         }
    }
    
    private void updateObjectFromTableSelection(){
        int row_selected = this.jTable.getSelectedRow();
        ArrayList<String> passLabel = new ArrayList<>(Arrays.asList(this.objectsFields));
        ArrayList<Component> content = new ArrayList<>();
        JTextArea[] inputArea = new JTextArea[this.objectsFields.length-1];
        
        for (int i = 0; i < this.objectsFields.length-1; i++) {
            inputArea[i] = new JTextArea();
            inputArea[i].setText((String)jTable.getValueAt(row_selected, i));
            content.add(inputArea[i]);
        }
        JComboBox yearInput = this.getYearInput();
        String yearValue = (String)jTable.getValueAt(row_selected, this.objectsFields.length-1);
        if(yearValue == null) yearInput.setSelectedItem("YY");
        else yearInput.setSelectedItem(yearValue);
        content.add(yearInput);
        
        JPanel newObjectPanel = getInputBox(passLabel, false, content);
        int result = JOptionPane.showConfirmDialog(this, newObjectPanel, "Update an  Object", JOptionPane.OK_CANCEL_OPTION);
        
        while (result == JOptionPane.OK_OPTION) {
            String objectName = inputArea[0].getText().trim();
            String orderNumber = inputArea[1].getText().trim();
            if (objectName.isEmpty() || orderNumber.isEmpty()) {
                JOptionPane.showMessageDialog(this, "Object or Ordernumber feild cannot be empty\n ", "Error", JOptionPane.ERROR_MESSAGE);
            }else{
                if(!objectName.equals(this.jTable.getValueAt(row_selected, 0)) && !this.jSearchObjects.isEnabled()){
                    int cancelUpdate = JOptionPane.showConfirmDialog(this, "Are u sure to update objectname? This may lead to update any service calls reference to this object!",
                            "Warning", JOptionPane.OK_CANCEL_OPTION);
                    if(cancelUpdate == JOptionPane.CANCEL_OPTION){
                        result = JOptionPane.showConfirmDialog(this, newObjectPanel, "Update an Object", JOptionPane.OK_CANCEL_OPTION);
                        continue;
                    }
                }
                
                QueryMessage newQuery; 
                ArrayList<String> updateFields = new ArrayList<>();
                ArrayList<String> updateValues = new ArrayList<>();
                ArrayList<Integer> updateType = new ArrayList<>();
                
                for (int i = 0; i < this.objectsFields.length - 1; i++) {
                    String input = inputArea[i].getText().trim();
                    if(!isStringEqual(input,(String)this.jTable.getValueAt(row_selected,i))){
                        updateFields.add(this.objectsFields[i]);
                        updateValues.add(input);
                        updateType.add(this.objectsFieldsType[i]);
                    }
                }
                String year = "";
                if (yearInput.getSelectedItem().equals("YY")) {
                    year = "";
                } else {
                    year += yearInput.getSelectedItem();
                }
                if(!isStringEqual(year,(String)this.jTable.getValueAt(row_selected,this.objectsFields.length-1))){
                    updateFields.add(this.objectsFields[this.objectsFields.length-1]);
                    updateValues.add(year);
                    updateType.add(this.objectsFieldsType[this.objectsFields.length-1]);
                }
                
                ArrayList<String> constraintFields = new ArrayList<>();
                ArrayList<String> constraintValues = new ArrayList<>();
                ArrayList<Integer> constraintType = new ArrayList<>();
                
                for(int i = 0; i < this.objectsFields.length; i++){
                    String objectInfo = (String)this.jTable.getValueAt(row_selected, i);
                    if(objectInfo != null){
                        constraintFields.add(this.objectsFields[i]);
                        constraintValues.add(objectInfo);
                        constraintType.add(this.objectsFieldsType[i]);
                    }
                }
               
                String updateTable = !this.jSearchObjects.isEnabled() ? "objects" : "objectspending";
                newQuery = new QueryMessage(QueryMessage.UPDATE, updateTable, 
                        updateFields,updateValues, updateType,
                        constraintFields,constraintValues,constraintType);

                newQuery = serverRountine(newQuery);
                if (newQuery == null) return;

                if (newQuery.queryStatus != 0) {
                    JOptionPane.showMessageDialog(this, "Fail to update the objects!\n " + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
                } else {
                    JOptionPane.showConfirmDialog(this, "Object updated!", "Message", JOptionPane.PLAIN_MESSAGE);
                    this.jRefreshMouseReleased(null);
                    break;
                }
            }
            result = JOptionPane.showConfirmDialog(this, newObjectPanel, "Update an Object", JOptionPane.OK_CANCEL_OPTION);
        }
    }
    
    private void updateServiceCallFromTableSelection(){
        int row_selected = this.jTable.getSelectedRow();
        ArrayList<String> passLabel = new ArrayList<>(Arrays.asList(this.serviceCallsFields));
        ArrayList<Component> content = new ArrayList<>();
        JPanel datePanel = this.prepareDateSelectPanel();
        for(int i = 0; i < this.serviceCallsFields.length; i++){
            if(this.serviceCallsFields[i].equals("Date")){
                String dateInput = (String)jTable.getValueAt(row_selected, i);
                if(dateInput != null){
                    StringTokenizer st = new StringTokenizer(dateInput, "/");
                    for (int j = 0; j < 3; j++) {
                        String temp = ""+Integer.parseInt(st.nextToken());
                        ((JComboBox) datePanel.getComponent(j)).setSelectedItem(temp);
                    }
                }
                content.add(datePanel);
            }
            else{
                JTextArea inputArea = new JTextArea();
                inputArea.setLineWrap(true);
                inputArea.setWrapStyleWord(true);
                inputArea.setText((String)jTable.getValueAt(row_selected, i));
                content.add(inputArea);
            }
        }
        JPanel newServiceCallPanel = getInputBox(passLabel, false, content); 
        JScrollPane showPanel = new JScrollPane(newServiceCallPanel);
        showPanel.setPreferredSize(this.serviceCallInputDim);
        int result = JOptionPane.showConfirmDialog(this, showPanel, "Update a Service Call", JOptionPane.OK_CANCEL_OPTION);
        
         while (result == JOptionPane.OK_OPTION) {
             String serviceName = ((JTextArea)content.get(0)).getText().trim();
             String serviceCallNo = ((JTextArea)content.get(1)).getText().trim();
             if(serviceName.isEmpty() || serviceCallNo.isEmpty())
                 JOptionPane.showMessageDialog(this, "Object or Service Call Number feild cannot be empty\n ", "Error", JOptionPane.ERROR_MESSAGE);
             else{
                 if(!serviceName.equals(this.jTable.getValueAt(row_selected, 0)) && !this.jSearchServiceCalls.isEnabled()){
                    int cancelUpdate = JOptionPane.showConfirmDialog(this, "Are u sure to update object? This may lead to error if the update object does not exist!",
                            "Warning", JOptionPane.OK_CANCEL_OPTION);
                    if(cancelUpdate == JOptionPane.CANCEL_OPTION){
                        result = JOptionPane.showConfirmDialog(this, showPanel, "Update an Service Call", JOptionPane.OK_CANCEL_OPTION);
                        continue;
                    }
                }
                 
                 QueryMessage newQuery;
                 String[] inputs = new String[this.serviceCallsFields.length];
                 boolean valid = true;
                 for(int i = 0; i < this.serviceCallsFields.length; i++){
                     if(this.serviceCallsFields[i].equals("Date")){
                         String[] dateString = new String[3];
                         int emptyCount = 0;
                         for(int j = 0; j < 3; j++){
                             dateString[j] = (String)((JComboBox)datePanel.getComponent(j)).getSelectedItem();
                             if(dateString[j].equals("DD") || dateString[j].equals("MM") || dateString[j].equals("YY")){
                                 emptyCount++;
                             }
                         }
                         if(emptyCount == 3){
                             inputs[i] = "";
                             continue;
                         }
                         else if(emptyCount < 3 && emptyCount > 0){
                             valid = false;
                             break;
                         }
                         inputs[i]  = dateString[0] + "/" +dateString[1] + "/" +dateString[2];
                     }
                     else{ 
                         String textInput = ((JTextArea)content.get(i)).getText();
                         inputs[i] = textInput.trim();
                     }
                 }
                 if(!valid){
                     JOptionPane.showMessageDialog(this, "Date input is wrong", "Error", JOptionPane.ERROR_MESSAGE);
                     result = JOptionPane.showConfirmDialog(this, showPanel, "Update a Service Call", JOptionPane.OK_CANCEL_OPTION);
                     continue;
                 }
                 ArrayList<String> updateFields = new ArrayList<>();
                 ArrayList<String> updateValues = new ArrayList<>();
                 ArrayList<Integer> updateType = new ArrayList<>();
                 for(int i = 0; i < this.serviceCallsFields.length; i++){
                     if(!isStringEqual(inputs[i],(String)this.jTable.getValueAt(row_selected, i))){
                         updateFields.add(this.serviceCallsFields[i]);
                         updateValues.add(inputs[i]);
                         updateType.add(this.serviceCallsFieldsType[i]);
                     }
                 }
                 
                 ArrayList<String> constraintFields = new ArrayList<>();
                 ArrayList<String> constraintValues = new ArrayList<>();
                 ArrayList<Integer> constraintType = new ArrayList<>();
                 for(int i = 0; i < this.serviceCallsFields.length;i++){
                     String serviceInfo = (String)this.jTable.getValueAt(row_selected, i);
                     if(serviceInfo != null){
                        constraintFields.add(this.serviceCallsFields[i]);
                        constraintValues.add(serviceInfo);
                        constraintType.add(this.serviceCallsFieldsType[i]);
                    }
                 }
                 String updateTable = !this.jSearchServiceCalls.isEnabled() ? 
                         "servicerecords" : "servicerecordspending";
                 newQuery = new QueryMessage(QueryMessage.UPDATE, updateTable, 
                        updateFields,updateValues, updateType,
                        constraintFields,constraintValues,constraintType);
                 
                newQuery = serverRountine(newQuery);
                if (newQuery == null) return;
                
                if (newQuery.queryStatus != 0) {
                    JOptionPane.showMessageDialog(this, "Fail to update the service call!\n " + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
                } else {
                    JOptionPane.showConfirmDialog(this, "Service call updated!", "Message", JOptionPane.PLAIN_MESSAGE);
                    this.jRefreshMouseReleased(null);
                    break;
                }
             }
             result = JOptionPane.showConfirmDialog(this, showPanel, "Update a Service Call", JOptionPane.OK_CANCEL_OPTION);
         }
    }
    
    private void generalSearchObjects(String keyword){
        ArrayList<String> outputFields = new ArrayList<>(Arrays.asList(this.objectsFields));
        ArrayList<String> constraintFields = new ArrayList<>();
        ArrayList<String> constraintValues = new ArrayList<>();
        ArrayList<Integer> constraintType = new ArrayList<>();
        ArrayList<Boolean> fuzzySearch = new ArrayList<>();
        
        for(int i = 0; i < this.objectsFields.length; i++){
            if(this.objectsFieldsType[i] == QueryMessage.STRING_TYPE){
                constraintFields.add(this.objectsFields[i]);
                constraintValues.add(keyword);
                constraintType.add(QueryMessage.STRING_TYPE);
                fuzzySearch.add(true);
            }
        }
        String searchTable;
        if(!this.jSearchObjects.isEnabled()) searchTable = "objects";
        else searchTable = "objectspending";
        
        QueryMessage newQuery = new QueryMessage(QueryMessage.GENERAL_SEARCH, searchTable, outputFields, constraintFields,
                        constraintValues, constraintType, fuzzySearch);
        newQuery = serverRountine(newQuery); if (newQuery == null) return;
        
        if (newQuery.queryStatus == 0) {
            Object[][] data = null;
            if(newQuery.result.isEmpty()){
                JOptionPane.showMessageDialog(this, "No result matched your search", "Empty", JOptionPane.INFORMATION_MESSAGE);
            }else{
                data = new Object[newQuery.result.size() / this.objectsFields.length][this.objectsFields.length];
                for(int i = 0; i < newQuery.result.size() / this.objectsFields.length; i++)
                    for(int j = 0; j < this.objectsFields.length; j++)
                        data[i][j] = newQuery.result.get(i*this.objectsFields.length+j);       
                
            }
           
            jTable.setModel(new DefaultTableModel(data, this.objectsFields));
            String[] highliterInput = new String[this.objectsFields.length];
            for(int i = 0; i < this.objectsFields.length; i++) highliterInput[i] = keyword;
            this.setHighlightTable(highliterInput);
            this.updateTableHeight();
            
        } else {
            JOptionPane.showMessageDialog(this, "Query Error:" + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
    
    private void generalSearchServiceCalls(String keyword){
        ArrayList<String> outputFields = new ArrayList<>(Arrays.asList(this.serviceCallsFields));
        ArrayList<String> constraintFields = new ArrayList<>();
        ArrayList<String> constraintValues = new ArrayList<>();
        ArrayList<Integer> constraintType = new ArrayList<>();
        ArrayList<Boolean> fuzzySearch = new ArrayList<>();
        
        for(int i = 0; i < this.serviceCallsFields.length; i++){
            if(this.serviceCallsFieldsType[i] == QueryMessage.STRING_TYPE){
                constraintFields.add(this.serviceCallsFields[i]);
                constraintValues.add(keyword);
                constraintType.add(QueryMessage.STRING_TYPE);
                fuzzySearch.add(true);
            }
        }
        String searchTable;
        if(!this.jSearchServiceCalls.isEnabled()) searchTable = "ServiceRecords";
        else searchTable = "ServiceRecordsPending";
        
        QueryMessage newQuery = new QueryMessage(QueryMessage.GENERAL_SEARCH, searchTable, outputFields, constraintFields,
                        constraintValues, constraintType, fuzzySearch);
        newQuery = serverRountine(newQuery); if (newQuery == null) return;
        
        if (newQuery.queryStatus == 0) {
            Object[][] data = null;
            if(newQuery.result.isEmpty()){
                JOptionPane.showMessageDialog(this, "No result matched your search", "Empty", JOptionPane.INFORMATION_MESSAGE);
            }else{
                data = new Object[newQuery.result.size() / this.serviceCallsFields.length][this.serviceCallsFields.length];
                for(int i = 0; i < newQuery.result.size() / this.serviceCallsFields.length; i++)
                    for(int j = 0; j < this.serviceCallsFields.length; j++)
                        data[i][j] = newQuery.result.get(i*this.serviceCallsFields.length+j);       
                
            }
           
            jTable.setModel(new DefaultTableModel(data, this.serviceCallsFields));
            String[] highliterInput = new String[this.serviceCallsFields.length];
            for(int i = 0; i < this.serviceCallsFields.length; i++) highliterInput[i] = keyword;
            this.setHighlightTable(highliterInput);
            setupServiceCallDim();
            
        } else {
            JOptionPane.showMessageDialog(this, "Query Error:" + newQuery.message, "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
    
    private boolean isStringEqual(String a, String b){
        if(a == null){
            if(b == null) return true;
            if(b.isEmpty()) return true;
            return false;
        }else if(a.isEmpty()){
            if(b == null) return true;
            if(b.isEmpty()) return true;
            return false;
        }else{
            if(b == null) return false;
            if(b.isEmpty()) return false;
            return a.equals(b);
        }
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Login().setVisible(true);
            }
        });


    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel huismanLabel;
    private javax.swing.JMenu jAccountMenu;
    private javax.swing.JMenu jAdminMenu;
    private javax.swing.JButton jApprove;
    private javax.swing.JPanel jApproveButtonPanel;
    private javax.swing.JMenu jApproveMenu;
    private javax.swing.JMenuItem jApproveObjects;
    private javax.swing.JMenuItem jApproveServiceCalls;
    private javax.swing.JButton jClearSearch;
    private javax.swing.JPanel jComplexPanel;
    private javax.swing.JButton jDeleteObject;
    private javax.swing.JButton jDeleteServiceCall;
    private javax.swing.JButton jDeleteUser;
    private javax.swing.JButton jExitButton;
    private javax.swing.JFileChooser jFileChooser;
    private javax.swing.JButton jGeneralSearch;
    private javax.swing.JTextField jGeneralSearchTextField;
    private javax.swing.JButton jGenerateServiceReport;
    private javax.swing.JButton jGetReport;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jLogin;
    private javax.swing.JButton jLoginButton;
    private javax.swing.JPanel jLoginInputs;
    private javax.swing.JPanel jLoginLabel;
    private javax.swing.JMenuItem jLogout;
    private javax.swing.JPanel jMainView;
    private javax.swing.JMenuItem jManageUsers;
    private javax.swing.JMenuBar jMenu;
    private javax.swing.JButton jNewObject;
    private javax.swing.JButton jNewServiceCall;
    private javax.swing.JButton jNewUser;
    private javax.swing.JButton jObjectAddServiceCall;
    private javax.swing.JPanel jObjectButtonPanel;
    private javax.swing.JPanel jObjectsSearchPanel;
    private javax.swing.JButton jOpenReportFolder;
    private javax.swing.JMenuItem jPassword;
    private javax.swing.JPasswordField jPasswordField;
    private javax.swing.JButton jPrint;
    private javax.swing.JButton jRefresh;
    private javax.swing.JButton jReject;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JMenu jSearchMenu;
    private javax.swing.JMenuItem jSearchObjects;
    private javax.swing.JButton jSearchObjectsButton;
    private javax.swing.JPanel jSearchObjectsButtonPanel;
    private javax.swing.JButton jSearchServiceCallButton;
    private javax.swing.JPanel jSearchServiceCallButtonPanel;
    private javax.swing.JMenuItem jSearchServiceCalls;
    private javax.swing.JPanel jServiceCallButtonPanel;
    private javax.swing.JPanel jServiceCallSearchPanel;
    private javax.swing.JScrollPane jServiceCallSearchScrollPanel;
    private javax.swing.JTable jTable;
    private javax.swing.JPanel jTablePanel;
    private javax.swing.JButton jUpdateUser;
    private javax.swing.JMenuItem jUploadReport;
    private javax.swing.JPanel jUserButtonPanel;
    private javax.swing.JTextField jUsernameField;
    private javax.swing.JButton jViewServiceCallObject;
    private javax.swing.JButton jViewServiceCalls;
    private javax.swing.JPanel jloginButtons;
    // End of variables declaration//GEN-END:variables

    private ObjectOutputStream getOutStream() throws IOException {
        OutputStream os = localSocket.getOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(os);
        return oos;
    }

    private ObjectInputStream getInputStream() throws IOException {
        InputStream is = localSocket.getInputStream();
        ObjectInputStream ois = new ObjectInputStream(is);
        return ois;
    }

    private JPanel getInputBox(ArrayList<String> labelName, boolean isPassword, ArrayList<Component> comp) {
        if (isPassword) {
            GridLayout layout = new GridLayout(labelName.size(), 2);
            JPanel panel = new JPanel(layout);
            for (int i = 0; i < labelName.size(); i++) {
                panel.add(new JLabel(labelName.get(i)));
                JPasswordField passField = new JPasswordField();
                panel.add(passField);
            }
            return panel;
        }

        JPanel panel = new JPanel(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.5;
        c.gridy = 0;
        c.weighty = 0.1;
        for (int i = 0; i < labelName.size(); i++) {
            c.gridx = i;
            JLabel newLabel = new JLabel(labelName.get(i), JLabel.CENTER);
            newLabel.setVerticalAlignment(JLabel.CENTER);
            panel.add(newLabel, c);
        }
        c.gridy = 1;
        c.weighty = 0.6;
        for (int i = 0; i < labelName.size(); i++) {
            c.gridx = i;
            JScrollPane scrollPane = new JScrollPane(comp.get(i));
            scrollPane.setPreferredSize(this.inputCellDim);
            panel.add(scrollPane, c);
        }

        return panel;
    }

    private void logoutProcedure() {
        this.localSocket = null;
        this.loginMsn = null;
        this.jMenu.setVisible(false);
        this.jMainView.setVisible(false);
        setAllfeaturesNotVisible();
        this.setSize(loginDim);
        this.jLogin.setVisible(true);
        this.jPasswordField.setText("");
        setWindowCenter();
        this.setResizable(false);
        this.setTitle("Welcome to Huisman Database");
        try {
            FileUtils.deleteDirectory(new File(this.tempDir));
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "Unable to delete temp folder!", "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }

    private void loginProcedure() {
        loginMsn = new LoginMessage(this.jUsernameField.getText().trim(),
                String.copyValueOf(this.jPasswordField.getPassword()).trim());
        if (loginMsn.username.isEmpty()) {
            JOptionPane.showMessageDialog(this, "Username field can not be empty!", "Error",
                    JOptionPane.ERROR_MESSAGE);
            loginMsn = null;
            return;
        }
        if (loginMsn.password.isEmpty()) {
            JOptionPane.showMessageDialog(this, "Password filed can not be empty!", "Error",
                    JOptionPane.ERROR_MESSAGE);
            loginMsn = null;
            return;
        }
        try {
            localSocket = new Socket(hostName, portNumber);
            this.getOutStream().writeObject(loginMsn);
            loginMsn = (LoginMessage) this.getInputStream().readObject();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Cannot connect to the server!\n " + e.getMessage(), "Error",
                    JOptionPane.ERROR_MESSAGE);
            localSocket = null;
            loginMsn = null;
            return;
        }

        if (!loginMsn.loginSucessful) {
            JOptionPane.showMessageDialog(this, "Connection Error\n " + loginMsn.loginErrorMsn, "Error",
                    JOptionPane.ERROR_MESSAGE);
            localSocket = null;
            loginMsn = null;
            return;
        }
        this.setTitle(loginMsn.username + " ,welcome back!");
        this.setLayout(new BorderLayout());
        this.setSize(this.objectViewDim);
        this.jMainView.setSize(this.objectViewDim);
        this.jLogin.setVisible(false);
        this.jMenu.setVisible(true);
        this.jMainView.setVisible(true);  
        this.setResizable(true);
        setWindowTop();
        this.enableMenuAndButtons();
        jSearchObjectsMouseReleased(null);
        switch(loginMsn.securitylevel){
            case SecurityLevel.ADMIN:
                break;
            case SecurityLevel.MANAGER:
                this.jManageUsers.setVisible(false);
                break;
            case SecurityLevel.COMMITOR:
                this.jAdminMenu.setVisible(false);
                this.jDeleteObject.setVisible(false);
                this.jDeleteServiceCall.setVisible(false);
                this.jApprove.setVisible(false);
                this.jReject.setVisible(false);
                break;
            case SecurityLevel.VIEWER:
                this.jAdminMenu.setVisible(false);
                this.jNewObject.setVisible(false);
                this.jDeleteObject.setVisible(false);
                this.jObjectAddServiceCall.setVisible(false);
                this.jNewServiceCall.setVisible(false);
                this.jDeleteServiceCall.setVisible(false);
                this.jApprove.setVisible(false);
                this.jReject.setVisible(false);
                break;
        }
        
    }
    
    private void enableMenuAndButtons(){
        this.jAdminMenu.setVisible(true);
        this.jManageUsers.setVisible(true);
        this.jNewObject.setVisible(true);
        this.jDeleteObject.setVisible(true);
        this.jObjectAddServiceCall.setVisible(true);
        this.jNewServiceCall.setVisible(true);
        this.jDeleteServiceCall.setVisible(true);
        this.jApprove.setVisible(true);
        this.jReject.setVisible(true);
    }
    
    private void setAllfeaturesNotVisible(){
        this.jTablePanel.setVisible(false);
        this.jUserButtonPanel.setVisible(false);
        this.jObjectButtonPanel.setVisible(false);
        this.jApproveButtonPanel.setVisible(false);
        this.jServiceCallButtonPanel.setVisible(false);
        this.jObjectsSearchPanel.setVisible(false);
        this.jServiceCallButtonPanel.setVisible(false);
        this.jRefresh.setVisible(false);
        this.jSearchObjectsButtonPanel.setVisible(false);
        this.jSearchServiceCallButtonPanel.setVisible(false);
        this.jPrint.setVisible(false);
        this.jGeneralSearch.setVisible(false);
        this.jComplexPanel.setVisible(false);
    }
    
    private void enableAllMenuItem(){
        this.jManageUsers.setEnabled(true);
        this.jUploadReport.setEnabled(true);
        this.jSearchObjects.setEnabled(true);
        this.jSearchServiceCalls.setEnabled(true);
        this.jApproveObjects.setEnabled(true);
        this.jApproveServiceCalls.setEnabled(true);
    }
    
    private QueryMessage serverRountine(Object newQuery) {
        QueryMessage result = null;
        try {
            this.getOutStream().writeObject(newQuery);
            result = (QueryMessage) this.getInputStream().readObject();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, "Server down!\n " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            logoutProcedure();
            return null;
        }
        return result;
    }
    
    private void setHighlightTable(String[] keywords) {
        TableColumnModel colModel = jTable.getColumnModel();
        for (int i = 0; i < jTable.getColumnCount(); i++) {
            TableColumn col = colModel.getColumn(i);
            if(keywords == null) col.setCellRenderer(new HighlightRender(""));
            else col.setCellRenderer(new HighlightRender(keywords[i]));
        }
    }
    
    private void setServiceCallTableWidth(){
        for(int i = 0; i < this.jTable.getColumnCount(); i++){
            TableColumn column = jTable.getColumnModel().getColumn(i);
            column.setPreferredWidth(this.serviceCallTableWidth[i]);
            
        }
        
//        for(int col = 0; col < jTable.getColumnCount(); col++){
//           TableColumn column = jTable.getColumnModel().getColumn(col);
//           int colWidth = column.getWidth();
//           for(int row = 0; row < jTable.getRowCount(); row++){
//               Component comp = jTable.prepareRenderer(jTable.getCellRenderer(row, col), row, col);
//               colWidth = Math.max(colWidth, comp.getPreferredSize().width);
//           }
//           column.setPreferredWidth(colWidth);
//        }
    }
    
    private void updateTableHeight(){
        for (int row = 0; row < jTable.getRowCount(); row++)
        {
            int rowHeight = jTable.getRowHeight();

            for (int column = 0; column < jTable.getColumnCount(); column++)
            {
                Component comp = jTable.prepareRenderer(jTable.getCellRenderer(row, column), row, column);
                rowHeight = Math.max(rowHeight, comp.getPreferredSize().height);
            }

            jTable.setRowHeight(row, rowHeight);
        }
    }
    
    private void setupServiceCallTableAndSearch(){
        this.setAllfeaturesNotVisible();
        this.enableAllMenuItem();
        this.jComplexPanel.setPreferredSize(this.serviceCallSearchDim);
        this.jServiceCallSearchPanel.setPreferredSize(this.serviceCallSearchInsideDim);
        
        jTable.setModel(new DefaultTableModel(null, this.serviceCallsFields));
        setupServiceCallDim();
        this.jTablePanel.setVisible(true);
        
        this.jSearchServiceCallButtonPanel.setVisible(true);
        this.jComplexPanel.setVisible(true);
        this.jRefresh.setVisible(true);
        this.jPrint.setVisible(true);
        this.jGeneralSearch.setVisible(true);
    }
    
    private void setupServiceCallDim(){
        jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        this.setServiceCallTableWidth();
        this.updateTableHeight();
        jTable.setPreferredScrollableViewportSize(this.serviceCallTableDim);
        this.jTablePanel.setPreferredSize(this.serviceCallTableDim);
        jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    }
    
    private void setupObjectTableAndSearch(){
        this.setAllfeaturesNotVisible();
        this.enableAllMenuItem();
        
        jTable.setModel(new DefaultTableModel(null, this.objectsFields));
        jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        jTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
        this.jScrollPane1.setPreferredSize(this.objectsTableDim);
        this.jTablePanel.setPreferredSize(this.objectsTableDim);
        
        this.jTablePanel.setVisible(true);
        this.jRefresh.setVisible(true);
        this.jObjectsSearchPanel.setVisible(true);
        this.jSearchObjectsButtonPanel.setVisible(true);
        this.jPrint.setVisible(true);
        this.jGeneralSearch.setVisible(true);
    }
}
